International e-mail

Visual Basic Code | ASP Code

The sample sends internationalized HTML e-mail: Note that you'll not need to do anything special (like using any of the properties and methods below) to enable international charsets in the message. The code below does this only for advanced purposes, like when you need to use non-UTF-8 in some parts of your e-mail.

SMTP.Message.ToUTF8 method is used to convert any text to UTF-8 charset. By default, MailBee already uses UTF-8 for outbound e-mails.

SMTP.Message.EncodeHeaderText method is used to encode particular headers into email-compliant form. Encoding is required if the header 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.

[Visual Basic]:

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", "Почта <postmaster@domain.com>", "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

[ASP]:

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", "Почта <postmaster@domain.com>", "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

 


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