How to Send HTML Email With VB.NET

Written by robmcclanahan
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Send HTML Email With VB.NET
(e-mail simbol image by vladislav susoy from Fotolia.com)

At some point as a programmer, a client will need you to build an application that sends e-mail. Whether you are sending out a weekly newsletter, or sending a notification to a user who registered for a website, Microsoft makes it easy to send e-mail in VB.NET via the System.Net.Mail namespace.

Skill level:
Easy

Other People Are Reading

Things you need

  • Visual Studio
  • SMTP server

Show MoreHide

Instructions

  1. 1

    Open Visual Studio and create a new console application by going to "File -> New Project."

  2. 2

    Open Module1.vb and add the following code to Sub Main to instantiate the email message:

    Dim mailMsg As New System.Net.Mail.MailMessage("from@example.com", "to@example.com", "This is an e-mail subject line", "This is the <strong>body</strong> of the email")

    Replace the strings above with the information you want in your e-mail.

  3. 3

    Add the following line to instantiate the SMTP client object:

    Dim smtpClient As New System.Net.Mail.SmtpClient("SMTP_Address")

    Replace "SMTP_Address" with the address to your SMTP server.

  4. 4

    Add the following line to tell the email message object that the email contains HTML:

    mailMsg.IsBodyHtml = True

  5. 5

    Add the following line to tell the SMTP client to send the email message:

    smtpClient.Send(mailMsg)

  6. 6

    Press F5 to build and run the application. After the application runs, check your e-mail!

Tips and warnings

  • Windows XP has a built-in SMTP server. You can install this feature by going to "Add or Remove Programs" and then "Add/Remove Windows Components." Under "Internet Information Services (IIS)" you should select "SMTP Services Component." Select this item and click "Next" and then "Finish" to install.
  • Window Vista and 7 do not come with a built-in SMTP service, so you will need to provide your own. There are many free applications available that you can use.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.