Send HTML Email in VB.NET
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: A simple VB.NET 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.
[VB.NET Example - Send HTML email]
The following example codes demonstrate how to use EASendMail SMTP component to send email in HTML body format. To get the full samples of EASendMail, please refer to Samples section.Imports EASendMail 'Add EASendMail namespace Module Module1 Sub Main() Dim oMail As New SmtpMail("TryIt") Dim oSmtp As New SmtpClient() ' Set sender email address, please change it to yours oMail.From = "test@emailarchitect.net" ' Set recipient email address, please change it to yours oMail.To = "support@emailarchitect.net" ' Set email subject oMail.Subject = "test HTML email from VB.NET project" ' Set HTML body oMail.HtmlBody = "<font size=5>This is</font> <font color=red><b>a test</b></font>" ' Your SMTP server address Dim oServer As New SmtpServer("smtp.emailarchitect.net") ' User and password for ESMTP authentication, if your server doesn't require ' User authentication, please remove the following codes. oServer.User = "test@emailarchitect.net" oServer.Password = "testpassword" ' If your SMTP server requires SSL/TLS connection, please add this line ' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto Try Console.WriteLine("start to send HTML email ...") oSmtp.SendMail(oServer, oMail) Console.WriteLine("email was sent successfully!") Catch ep As Exception Console.WriteLine("failed to send email with the following error:") Console.WriteLine(ep.Message) End Try End Sub End ModuleAfter 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 ImportHtmlBody 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.

sumber: http://www.emailarchitect.net/easendmail/kb/vbnet.aspx?cat=6
Tidak ada komentar:
Posting Komentar