Creating and sending HTML-formatted messages (Part 5)

Advanced topics Summary: Covers body and alternative body encoding usage and limitations. Compares encoding methods available in MailBee (Quoted-Printable and Base64).

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 documents may contain symbols that are not allowed by email standards. For example, some mail gateways truncate all 8bit symbols to 7bit making it's impossible for extended characters (with ASCII codes bigger than 127) to pass through such gateways.

The process of encoding converts source text into form that can be freely transmitted by all mail gateways. Once received, the text is decoded, and original text is restored.

Different encoding methods fit better for different text patterns. If the source contains mostly 7bit characters, Quoted-Printable encoding is preferred. Base64 encoding is more suitable for binary data (binaries usually contain lots of 8bit characters) or for texts written in extended charsets such as UTF-8 or Cyrillic.

Default BodyEncoding setting is Quoted-Printable (QP for short).

Note 1: You might need to change default encoding setting only if you are concerned about the message body size (in some cases, Quoted-Printable is more space-consuming than Base64 or "no encoding" encodings) or if you have to support very old e-mail clients which do not support Quoted-Printable (in this case, you should use "no encoding" method BodyEncoding=0).

Note 2: The side (usually positive) effect of using Base64 or Quoted-Printable encoding instead of "no encoding" is keeping original line-wrapping of plain-text content (see FAQ for details).


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"

' Put extended char (trademark character) into the body
Mailer.Message.BodyText = "<html><body>MailBeeT</body></html>"

' Set HTML format for the body
Mailer.Message.BodyFormat = 1

' Force Quoted-Printable (QP) encoding.
' However, QP is a default setting, so the next
' line can be omitted, and shown for clarity only
Mailer.Message.BodyEncoding = 2

Mailer.Send
Mailer.Disconnect

If the message includes alternative body (AltBodyText is non-empty), it's recommended to encode this body too.

AltBodyEncoding property sets encoding method for AltBodyText in the same manner as BodyEncoding sets encoding for BodyText.


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"

' Put extended char (trademark character) into HTML body
Mailer.Message.BodyText = "<html><body>MailBeeT</body></html>"

' Put extended char (trademark character) into plain-text body
Mailer.Message.AltBodyText = "MailBeeT"

' Set HTML format for the body
Mailer.Message.BodyFormat = 1

' Enable Base64 encoding.
' In fact, QP is more efficient here,
' so Base64 is used for illustration purposes only.
Mailer.Message.AltBodyEncoding = 3

' Enable QP encoding to illustrate that
' HTML body and plain-text body can use
' different encoding methods
Mailer.Message.BodyEncoding = 2

Mailer.Send
Mailer.Disconnect

See Also:

BodyEncoding Property
AltBodyEncoding Property


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