ANSMTP Developers Center > Internationalization with ANSMTP

Introduction

This tutorial shows how to choose a correct character set for your email.

Character Set

If there are some non-ASCII characters in your email, you should specify Charset property to help the email client to learn what is the current character set so that current email can be displayed correctly. We also recommend you set HeaderEncoding property to 1.

The following code demonstrates how to send email with Simplified Chinese.

Private Sub SendEmail()
  Dim oSmtp As ANSMTPLib.OBJ
  Set oSmtp = New ANSMTPLib.OBJ

  oSmtp.Charset = "gb2312"
  oSmtp.HeaderEncoding = 1
  oSmtp.ServerAddr = "mail.adminsystem.net"  
  oSmtp.FromAddr = "test@adminsystem.net"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.net", 0

  oSmtp.Subject = "Test"
  'suppose that there are some Simplified Chinese characters in email body.
  oSmtp.BodyText = "Hello, this is a test...." 
 
  If oSmtp.SendMail() = 0 Then
    MsgBox "Message delivered!"
  Else
    MsgBox oSmtp.GetLastErrDescription()
  End If
End Sub					

Code Page and UNICODE

Sometimes even we have set Charset and HeaderEncoding properties to the correct value, Asian language characters still appear as ??? in email body. It is likely that the Asian language has not been installed on your machine or this language is not your default language.

Firstly, you should install East Asian Languages on your machine. Secondly, you should set this Asian language as default language for non-UNICODE program.

How to install Asian languages on my machine?
Control Panel->Regional and Languages Options->Languages

How to set default language for non-UNICODE program?
Control Panel->Regional and Languages Options->Advanced

If you don't want to set this Asian language as your default language, you should use CodePage property to specify current codepage of current email

Private Sub SendEmail()
  Dim oSmtp As ANSMTPLib.OBJ
  Set oSmtp = New ANSMTPLib.OBJ

  oSmtp.CodePage = 936 'code page of Simplified Chinese
  oSmtp.Charset = "gb2312"
  oSmtp.HeaderEncoding = 1
  oSmtp.ServerAddr = "mail.adminsystem.net"  
  oSmtp.FromAddr = "test@adminsystem.net"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.net", 0

  oSmtp.Subject = "Test"
  'suppose that there are some Simplified Chinese characters in email body.
  oSmtp.BodyText = "Hello, this is a test...." 
 
  If oSmtp.SendMail() = 0 Then
    MsgBox "Message delivered!"
  Else
    MsgBox oSmtp.GetLastErrDescription()
  End If
End Sub					

How does it work?

Because all strings in COM interface are in UNICODE, but all string are in single-byte in sending email by TCP/IP. If you don't specify code page to ANSMTP, ANSMTP will use the default code page to convert UNICODE to single-byte. If you want to send email which contains the non default language characters, you should specify the corresponding code page to ANSMTP.

UTF-8 Encoding

UTF-8 uses multiple single bytes to represent non-ASCII characters, so UTF-8 supports all languages very well, the following code can help you to send email with any languages.

Private Sub SendEmail()
  Dim oSmtp As ANSMTPLib.OBJ
  Set oSmtp = New ANSMTPLib.OBJ

  oSmtp.CodePage = 65001 'code page of utf-8
  oSmtp.Charset = "UTF-8"
  oSmtp.HeaderEncoding = 1
  oSmtp.ServerAddr = "mail.adminsystem.net"  
  oSmtp.FromAddr = "test@adminsystem.net"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.net", 0

  oSmtp.Subject = "Test"
  oSmtp.BodyText = "Hello, this is a test...." 
 
  If oSmtp.SendMail() = 0 Then
    MsgBox "Message delivered!"
  Else
    MsgBox oSmtp.GetLastErrDescription()
  End If
End Sub					

Note*: Not all email client support UTF-8 decoding, sometimes you have to specify the corresponding code page based upon your situation.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your SMTP server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2008 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map