Creating and sending HTML-formatted messages
(Part 4)
Building alternative message body
Summary: Discusses various
methods of supplying alternative plain-text body in addition to main HTML body
of the message.
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
See Also:
Part 5 (Advanced
topics)
ImportAltBodyText Method
GetPlainFromHtml Method
AltBodyText Property
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.