HTML emails provide your users with an interactive message. These emails incorporate links and images, so users can view your products; this type of email is also frequently used for newsletters, follow-up communication and sales. Visual Basic (VB) is a part of the Microsoft .NET framework, which gives you the tools necessary to send HTML emails to your customers. Sending an HTML email is similar to sending a text email in VB, but it requires HTML input for the email body.
Create your email and HTML variables. The email variable calls the class library used to send email in VB. The HTML variable contains the email's body. In this example, the HTML email is a simple letter that contains bold text. The following code shows you how to create variables in VB:
Dim email As New MailMessage()
Dim theEmail As String
Assign a message body to the "theEmail" variable. The code value you use is converted to an HTML message. The message can contain images, tables, links and formatted text. The following code creates an HTML email string:
theEmail = "<b>Buy Now</b> <a email@example.com'>Click here</a> "
Set up the email message properties. Several properties are required to send the email. The email class requires the recipient and send email, message body and format properties. The following code sets up your email object:
email.To = "firstname.lastname@example.org"
email.From = "email@example.com"
email.Subject = "This is an HTML email sample."
email.BodyFormat = MailFormat.Html
email.Body = theBody
Set up the server to relay the message. Each time you send email, an outgoing SMTP server is used. The SMTP value is found in your email client software settings, or it is provided by your Internet Service Provider (ISP). The following code sets up the outgoing email email server for VB:
SmtpMail.SmtpServer = "smtp.outgoing_server.com" 'this value is replaced with the SMTP server provided by your ISP
Send the email. A simple "Send" command is used to send your recipient the email. The following code executes the HTML command and sends it to your recipient:
- Photo Credit aqua email image by Ruslana Stovner from Fotolia.com
How to Send an Email via G-Mail in Visual Basic 6
Visual Basic 6 (VB6) is Microsoft's take on the classic Basic computer programming language. The VB6 version of the language and the...
How to Create Forms With Visual Basic
Since it was first released by Microsoft in 1987, Visual Basic (VB) has developed into one of the United States' leading programming...
How to Create an Email in a VBScript
Visual Basic Scripting (VB Scripts) is a type of Visual Basic programming that is used in text files. The Windows operating system...
How to Read Email in VB
Visual Basic (VB) provides developers with powerful tools that interact with users' desktops. One way to use the VB platform is to...
How to Declare a Variable in Visual Basic
In programming, variables are words that are assigned to reference the locations in the computer's memory where data can be stored. This...