In previous section, I introduced how to send email without specified SMTP server. In this section, I will introduce how to compose and send HTML email in VB 6.0.
If you want to specify the font, color or insert pictures in your email, you should use Html email format instead of Plain text email format.
Remarks: All of samples in this section are based on first section: Send email in a simple VB 6.0 project. To compile and run the following example codes successfully, please click here to learn how to create the test project and add reference of EASendMail to your project.
The following example codes demonstrate how to send email in HTML body format in VB6.
To get the full sample projects, please refer to Samples section.
Private Sub Command1_Click() Dim oSmtp As New EASendMailObjLib.Mail oSmtp.LicenseCode = "TryIt" ' Set your sender email address oSmtp.FromAddr = "email@example.com" ' Add recipient email address oSmtp.AddRecipientEx "firstname.lastname@example.org", 0 ' Set email subject oSmtp.Subject = "test HTML email from VB 6.0 project" ' Set HTML body format oSmtp.BodyFormat = 1 ' Set HTML body text oSmtp.BodyText = "<font size=5>This is</font> <font color=red><b>a test</b></font>" ' Your SMTP server address oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication, if your server doesn't require ' User authentication, please remove the following codes. oSmtp.UserName = "email@example.com" oSmtp.Password = "testpassword" ' If your smtp server requires SSL connection, please add this line ' oSmtp.SSL_init MsgBox "start to send email ..." If oSmtp.SendMail() = 0 Then MsgBox "email was sent successfully!" Else MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription() End If End Sub
After you received the email by your email client, the body text is like this:
Of course, you don’t have to write the HTML source body text in your application manually. You can build a html file with HTML tools and use ImportMailEx method to import the html file directly.
You can also refer to the htmlmail.* samples in EASendMail Installer. Those samples demonstrate how to build a HTML email editor and send HTML email with attachment or embedded images/pictures.
At next section I will introduce how to attach file attachment to email message.
If you have any comments or questions about above example codes, please click here to add your comments.