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:
Other People Are Reading
Things you need
- Visual Studio
- SMTP server
Open Visual Studio and create a new console application by going to "File -> New Project."
Open Module1.vb and add the following code to Sub Main to instantiate the email message:
Dim mailMsg As New System.Net.Mail.MailMessage("email@example.com", "firstname.lastname@example.org", "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.
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.
Add the following line to tell the email message object that the email contains HTML:
mailMsg.IsBodyHtml = True
Add the following line to tell the SMTP client to send the email message:
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.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for