Ads

Captured Technology - Blog

Sending eMails within a .Net Application

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
 533  246383  3/28/2024

Translate

Categories

Blog Calendar