Creating and sending HTML-formatted messages (Part 2)

Importing HTML file into message body Summary: Briefly explains how to import HTML file into the message body and automatically attach pictures and other objects this HTML file depends on.

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

Message.ImportBodyText method reads content of the file specified in FilePath parameter into the message body. This is the only required parameter of ImportBodyText method.

Because message body may have various formats (usually plain-text and HTML), ImportBodyText also supports optional parameter HTMLImport that denotes whether to treat the content as plain-text or as HTML.

If HTMLImport=False (this is default value), the file content is just copied into message body and the body is marked as plain-text.

If used for importing HTML (HTMLImport=True), the body is marked as HTML, and ImportBodyText method also parses imported HTML document looking for any objects related to the document (such as images, scripts and stylesheets). Every object found is appended to the message as inline attachment.


Code example:

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.site.com"

Mailer.Message.ToAddr = "Bill Smith<bill@server1.com>, Dex<dex1979@server2.com>"
Mailer.Message.FromAddr = "John Doe <jdoe@site.com>"
Mailer.Message.Subject = "This is HTML message"

' Import "email.htm" file as HTML (including embedded pictures, scripts, etc.)
' If related images/scripts/etc are available on the disk, they will be added as
' inline attachments (i.e. embedded objects)
Mailer.Message.ImportBodyText "C:\docs\email.htm", True

Mailer.Send
Mailer.Disconnect

See Also:

Part 3 (Assembling body text from different sources)

ImportBodyText Method


Copyright © 2002-2022, AfterLogic Corporation. All rights reserved.