CapturedTech.com

Captured Technology

Sending eMails within a .Net Application

Dec 29 2008

Sending eMails within a .Net application is fairly simple with the use of the System.Net.Mail namespace.

First, import the class:

Imports System.Net.Mail

Then create a function to provide for sending the emails within a public class:

Public Shared Function SendEmail(ByVal strFrom As String, _
                       ByVal strTo As String, _ 
                       ByVal strSubject As String, _
                       ByVal strBody As String) As MailMessage 
        Dim objReturn As New MailMessage 

        Try 
            Dim objMail As New MailMessage(strFrom, strTo) 
            objMail.Subject = strSubject 
            objMail.Body = strBody 
            Dim SmtpMail As SmtpClient = New SmtpClient("smtp.mail.com") 
            SmtpMail.Send(objMail) 
            objReturn = objMail 
        Catch ex As Exception 
            objReturn = Nothing 
        End Try 

        Return objReturn 
    End Function

The Smtp client will be your local client.

Call this function from anywhere within your application or webpage.

Blog Directory

Latest technology news.
 Patrick Stevens
 556  246509  12/18/2024

FaceBook

Translate