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 

            Dim objMail As New MailMessage(strFrom, strTo) 
            objMail.Subject = strSubject 
            objMail.Body = strBody 
            Dim SmtpMail As SmtpClient = New SmtpClient("") 
            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
 535  246400  4/11/2024