International e-mail (MailBee Objects Tutorials)

From AfterLogic Wiki

Jump to: navigation, search

The sample sends internationalized HTML e-mail:

  • The message's HTML body contains "Text" word printed in Simplified Chinese, Korean and Cyrillic. To allow mixing different languages in the same document, UTF-8 charset is used (UTF stands for "Unicode Transformation Format")
  • "Subject:" field contains "??" ("Hello" in Simplified Chinese). Charset is "gb-2312"
  • "From:" field contains e-mail address whose friendly name is written in Cyrillic ("windows-1251" charset)

SMTP.Message.ToUTF8 method is used to convert any text to UTF-8 charset. You need this method only if you want to create and send Unicode e-mails.

SMTP.Message.EncodeHeaderText method is used to encode particular headers into email-compliant form. Encoding is required if the header text:

  • exceeds maximum allowed length (> 60 chars)
  • contains extended characters which cannot be represented in 7bit chars. Some old e-mail gateways do not support extended characters
  • presented in charset different from the message body's charset (e.g. the body is "UTF-8" and the Subject is "gb-2312")
  • contains multi-line text

SMTP.Message.Charset property specifies charset of the body. This charset is also used as default charset for the headers.

For simplicity, SMTP authentication is not used and no error-checking is performed.

Dim objSMTP, strTemp
 
' Create mailer component
Set objSMTP = CreateObject("MailBee.SMTP")
 
' Unlock SMTP component
objSMTP.LicenseKey = "put your license key here"
 
' Set SMTP server name
objSMTP.ServerName = "mail.server.com"
 
' Encode "From:" value as Cyrillic
strTemp = objSMTP.Message.EncodeHeaderText("From", "Ïî÷òà ", "windows-1251", 2)
 
' Assign encoded "From:" value to corresponding header
objSMTP.Message.FromAddr = strTemp
 
' Set "To:" value, no encoding is required here
' since no international characters were used
objSMTP.Message.ToAddr = "recipient@anotherdomain.com"
 
' Encode "Subject:" value as Simplified Chinese
strTemp = objSMTP.Message.EncodeHeaderText("Subject", "??", "gb-2312", 3)
 
' Assign encoded "Subject:" value to corresponding header
objSMTP.Message.Subject = strTemp
 
' Set HTML format for the body
objSMTP.Message.BodyFormat = 1
 
' Mark that body content is composed with UTF-8 charset
objSMTP.Message.Charset = "UTF-8"
 
' Compose HTML body using UTF-8 charset:

' Prepare HTML HEAD section. ToUTF8 is used here for clarity only
' (since UTF-8 representation of US characters is the same as their
' native representation)
strTemp = objSMTP.Message.ToUTF8("<html><head>" & _
  "<meta content=""text/html; charset=UTF-8"" http-equiv=Content-Type>" & _
  "</head><body>" & _
  "Word ""Text"" in Simplifed Chinese, Korean and Cyrillic:<br>")
 
' Print "Text" in Simplified Chinese
strTemp = strTemp & objSMTP.Message.ToUTF8("Îı¾<br>", "gb2312")
 
' Print "Text" in Simplified Korean
strTemp = strTemp & objSMTP.Message.ToUTF8("¿øº»<br>", "EUC-KR")
 
' Print "Text" in Cyrillic
strTemp = strTemp & objSMTP.Message.ToUTF8("Òåêñò</body></html>", "windows-1251")
 
' Assign UTF-8 content to the message body
objSMTP.Message.BodyText = strTemp
 
' Send the message
objSMTP.Send
<%
Dim objSMTP, strTemp
 
' Create mailer component
Set objSMTP = Server.CreateObject("MailBee.SMTP")
 
' Unlock SMTP component
objSMTP.LicenseKey = "put your license key here"
 
' Set SMTP server name
objSMTP.ServerName = "mail.server.com"
 
' Encode "From:" value as Cyrillic
strTemp = objSMTP.Message.EncodeHeaderText("From", "Ïî÷òà ", "windows-1251", 2)
 
' Assign encoded "From:" value to corresponding header
objSMTP.Message.FromAddr = strTemp
 
' Set "To:" value, no encoding is required here
' since no international characters were used
objSMTP.Message.ToAddr = "recipient@anotherdomain.com"
 
' Encode "Subject:" value as Simplified Chinese
strTemp = objSMTP.Message.EncodeHeaderText("Subject", "??", "gb2312", 2)
 
' Assign encoded "Subject:" value to corresponding header
objSMTP.Message.Subject = strTemp
 
' Set HTML format for the body
objSMTP.Message.BodyFormat = 1
 
' Mark that body content is composed with UTF-8 charset
objSMTP.Message.Charset = "UTF-8"
 
' Compose HTML body using UTF-8 charset:
 
' Prepare HTML HEAD section. ToUTF8 is used here for clarity only
' since UTF-8 representation of US characters is the same as their
' native representation
strTemp = objSMTP.Message.ToUTF8("<html><head>" & _
  "<meta content=""text/html; charset=UTF-8"" http-equiv=Content-Type>" & _
  "</head><body>" & _
  "Word ""Text"" in Simplifed Chinese, Korean and Cyrillic:<br>")
 
' Print "Text" in Simplified Chinese
strTemp = strTemp & objSMTP.Message.ToUTF8("Îı¾<br>", "gb2312")
 
' Print "Text" in Simplified Korean
strTemp = strTemp & objSMTP.Message.ToUTF8("¿øº»<br>", "EUC-KR")
 
' Print "Text" in Cyrillic
strTemp = strTemp & objSMTP.Message.ToUTF8("Òåêñò</body></html>", "windows-1251")
 
' Assign UTF-8 content to the message body
objSMTP.Message.BodyText = strTemp
 
' Send the message
objSMTP.Send
%>

See Also:
Charset Property
EncodeHeaderText Method
ToUTF8 Method