Our Sites:  Tutorial Buzz  |  How To Tree  |  Recipe Voice  |  Golf Twist  |  DIY Click  |  Movie Lizard  |  Halloween Twist  
<
Search:
Submit Link
Mail to a Friend
RSS FeedReceive updates via our RSS feed

Creating and sending HTML email in Visual Basic - Part 4

by: AfterLogic

Building alternative message body
This tutorial shows various methods of supplying alternative plain-text body in addition to main HTML body of the message using AfterLogic's MailBee SMTP component in Visual Basic.

Tutorial map:
Part 1 - Sending simple HTML e-mail
Part 2 - Importing HTML file into message body
Part 3 - Assembling body text from different sources
Part 4 - Building alternative message body
Part 5 - Advanced topics

HTML-formatted email messages often provide plain-text version of their content (it is called alternative body). If alternative body is present in a message such message can be also viewed with older email clients that do not provide HTML support.

If you already have text file that you want to be used as alternative message body, use ImportAltBodyText method.

Code example:

' The code below is common for all examples in this topic

Dim Mailer

' Using Visual Basic to create object
Set Mailer = CreateObject("MailBee.SMTP")

' Using ASP to create object
' Set Mailer = Server.CreateObject("MailBee.SMTP")

Mailer.LicenseKey = "put your license key here"
Mailer.ServerName = "mail.server.com"

' The code below is specific to this sample

Mailer.Message.ToAddr = "bill@yoursite.com"
Mailer.Message.FromAddr = "joe@mysite.com"
Mailer.Message.Subject = "Hello"

' Import "email.htm" into HTML body
Mailer.Message.ImportBodyText "C:\docs\email.htm", True

' Import plain-text version of email into plain-text body
Mailer.Message.ImportAltBodyText "C:\docs\email.txt"

Mailer.Send

However, if plain-text version of the body is not available, MailBee can create it for you.

MakeAltBody method of the Message object converts value of BodyText property into plain form and places the result into AltBodyText property's value.

Code example:

' The code below is common for all examples in this topic

Dim Mailer
' Using Visual Basic to create object
Set Mailer = CreateObject("MailBee.SMTP")

' Using ASP to create object
' Set Mailer = Server.CreateObject("MailBee.SMTP")

Mailer.LicenseKey = "put your license key here"
Mailer.ServerName = "mail.server.com"

' The code below is specific to this sample

Mailer.Message.ToAddr = "bill@yoursite.com"
Mailer.Message.FromAddr = "joe@mysite.com"
Mailer.Message.Subject = "Hello"

' Import email.htm into HTML body
Mailer.Message.ImportBodyText "C:\docs\email.htm", True

' Generate alternative plain-text body from HTML body
Mailer.Message.MakeAltBody

Mailer.Send
Mailer.Disconnect

Finally, you can generate alternative body manually. Also, you can create alternative body using MakeAltBody method and then manually edit generated alternative body.

Alternative body content is actually stored in AltBodyText property. You can read or modify it the same way as BodyText property.

Note: Unlike BodyFormat, there is no AltBodyFormat property because alternative body is always plain-text.

Code example:

' The code below is common for all examples in this topic

Dim Mailer

' Using Visual Basic to create object
Set Mailer = CreateObject("MailBee.SMTP")

' Using ASP to create object
' Set Mailer = Server.CreateObject("MailBee.SMTP")

Mailer.LicenseKey = "put your license key here"
Mailer.ServerName = "mail.server.com"

' The code below is specific to this sample

Mailer.Message.ToAddr = "bill@yoursite.com"
Mailer.Message.FromAddr = "joe@mysite.com"
Mailer.Message.Subject = "Hello"

' Import email.htm into HTML body
Mailer.Message.ImportBodyText "C:\docs\email.htm", True

' Generate alternative plain-text code using
' another method (which allows to get plain-text
' version of any HTML source, not necessarily
' BodyText property value)

Mailer.Message.AltBodyText = _
Mailer.Message.GetPlainFromHtml(Mailer.Message.BodyText)

Mailer.Send
Mailer.Disconnect

About AfterLogic
AfterLogic specializes in email and messaging components. You can visit AfterLogic at http://www.afterlogic.com/. Here you can download evaluations for all their email and messaging components and get support.

© Copyright 2002-2005 Afterlogic, an iForum LLC division

The ASP.NET 2.0 Anthology: 101 Essential Tips, Tricks & Hacks is a collection of solutions to the most common ASP.NET problems. Let five world-class ASP.NET professionals guide you through countless practical solutions using C#. Learn the most practical features and best approaches for ASP.NET.
 
Get your FREE 156 Page Preview!

Home  |  News  |  Source Code  |  Tutorials  |  Components  |  Tools  |  Books  |  Free Magazines  |  Jobs  |  Gear  |  Hosting  |  Links
 
Copyright © 2000 - 2006 Code Beach  |    |  Privacy Policy
 
Free thumbnail preview by Thumbshots.org