Sometime we may need to send readable mail with Simplified Chinese characters programmatically with CDO 2.0 in our application, web application etc. It is one common scenario in real world in China. It will be very easy in Windows 2000 platform because we can use CDO 2.0 for Windows 2000 object library.
2. More information
For Internet mails, the proper Charset Property should be defined properly before sending the mail according with the language used in the mail. The following is the correct Charset list for some common language for Internet mails.
Language CharSet
Simplified Chinese gb2312
Traditional Chinese big5
English iso-8859-1
If the Charset used doesn’t match with the language in the Internet mails, the mails may be not readable.
3. Sample codes and how to use it
You can perform the following steps to test the sample codes.
1. Create one Windows Application project in VB 6.0. Click menu Project -> Reference… -> check “Microsoft CDO 2.0 for Windows 2000” and “Microsoft ActiveX Data Object library 2.6” in “Available Reference” list.
2. In the VB form, drag two textbox controls, one commandbutton control on it. Name them as txtSubject, txtMailbody and cmdSendMail.
3. Double click the commandbutton control, then copy the following codes between line “Private Sub cmdSendMail_Click()” and line “End Sub”.
Dim iConf As CDO.Configuration
Set iConf = CreateObject("CDO.Configuration")
Dim Flds As ADODB.Fields
Set Flds = iConf.Fields
‘Send the message using the network (SMTP protocol over the network).
5. In Windows form, type in some Simplified Chinese characters into txtSubject and txtMailbody controls, then click cmdSendMail button.
6. In Client, you will see readable mails with Simplified Chinese characters.
7. If you use switch from line
iBP.Charcet=”gb2312”
to
iBP.Charcet=”iso-8859-1”
You will see the mail with Simplified Chinese characters are not readable because we use wrong Charcet (iso-8859-1 is for English language) for the mail with Simplified Chinese characters.
4. Reference
The CdoProtocolsAuthentication enumeration is used to specify the mechanism used when authenticating to a Simple Mail Transfer Protocol (SMTP) service over the network.
Name
Value
Description
cdoAnonymous
0
Do not authenticate.
cdoBasic
1
Use basic (clear-text) authentication. The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.
cdoNTLM
2
Use NTLM authentication (Secure Password Authentication in Microsoft® Outlook® Express). The current process security context is used to authenticate with the service.