To include automated mail sending in your code, simply import System.Net and System.Net.Mail in your code:

Imports System.Net
Imports System.Net.Mail
and on your calling function simply make a call to SmtpClient.Send()

Dim yourMail As SmtpClient = New SmtpClient("")

SmtpClient.Send() have two overloaded function calls

1. SmtpClient.Send(message as System.Net.MailMessage)
2. SmtpClient.Send(from as String, recipients as String, subject as String, Body as String)

To customize your message you may use System.Net.Mail.MailMessage(). Example:

            Dim theMessage As MailMessage = New MailMessage

            theMessage.From = New MailAddress("")
            theMessage.Subject = "The Subject"
            theMessage.Body = "The body bla bla bla."

To send message as html just assign MailMessage.isBodyHtml to true:

            theMessage.IsBodyHtml = True 
            theMessage.Body = "<HTML><HEAD>Subject</HEAD>" + _
                                            "<BODY>your body bla bla bla</BODY></HTML>"

            Dim theMail As SmtpClient = New SmtpClient("yourmailserver.local.domain")

            theMail.Credentials = New NetworkCredential("username", "password")

Comments are closed.

    About the author

    The author have 12+ years experience in IT Industry with varying job roles from system developer/analyst/consultant positions. Majority of her development, implementation and systems support background focus on Financial/Banking/Credit Solutions.


    October 2010


    VB .Net

    RSS Feed