System.Web.Mail FAQ

Complete FAQ Listing


3.1 How do I send non US-ASCII emails? Printer Friendly   Email This FAQ   Discuss

In the beginning, when email was first being used, it was all us-ascii content. To handle different languages and character sets, different encodings must be used. The following example demonstrates sending a non us-ascii email, using the Chinese GB2312 character set as an example. The hardest part of sending non us-ascii email, is to determine the correct character set. For reference, an easy to use character set chart can be found at aspNetEmail's website, here: http://www.aspnetemail.com/charsets.aspx .

Note: There is one major pitfall with this technique. The original email rfcs required that all non us-character sets use the quoted-printable or base64 content transfer encoding (convert all characters above 127, to 2 or more bytes, so the individual byte value is less than 128). Email readers, then take these bytes, and convert them back to the original character set. System.Web.Mail does not encode higher end character sets. Instead, it just sends the characters unencoded (commonly known in the email world as 8 bit encoding). Thus, if your email recipient's mail server, or gateway, does not support 8 bit encoding, they will not receive the email. THERE IS NO WAY PROGRAMMATIC WAY OF CHECKING FOR THIS. The only way, is make sure the email message is properly encoded using the quoted-printable (preferred) or base64 content transfer encoding. If you are sending a newsletter, this can be a huge problem, because your newsletter will simply not be delivered, and there is a good chance, you will never know it. As an email vender, I've had customer after customer encounter this problem. And it has always been fixed by using the quoted-printable format. Because this cannot be controlled using System.Web.Mail, you will need to use a third party product like aspNetEmail. The bottom line is this: if you need to send emails, using a higher end character set, DO NOT USE System.Web.Mail. Either roll your own component (if you have the time), or purchase a third party product that properly encodes email messages.

For those people that don't have a choice, and have to use System.Web.Mail, the following is a code snippet demonstrating sending a non us-ascii email.
 
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some Chinese characters or text goes here";
mail.BodyEncoding = System.Text.Encoding.GetEncoding( "GB2312" ); //set the proper character set here
SmtpMail.SmtpServer = "localhost";  //your real server goes here
SmtpMail.Send( mail );

[ VB.NET ]
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "Some Chinese characters or text goes here"
mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312") 'set the proper character set here
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

 

Discuss This FAQ Item
Got a question? Another Suggestion? Want to post your solution? Discuss it below.
New Post
  • sample in the case of sending Japanese mail.    [ Reply ]
  • Message error    [ Reply ]
  • Exclamation Points    [ Reply ]
    • RE: Exclamation Points    [ Reply ]
      • RE RE: Exclamation Points    [ Reply ]
  • Non US-ASCII emails in ASP    [ Reply ]
  • US-ASCII    [ Reply ]
  • subject encode    [ Reply ]
  • how to send data in datagrid to email    [ Reply ]
  • how do I send a URI more than one line in email body?    [ Reply ]
  • EMail Failure for some domains. *****Very Urgent*****    [ Reply ]
    • RE: EMail Failure for some domains. *****Very Urgent*****    [ Reply ]
  • Decryption    [ Reply ]
    • RE: Decryption    [ Reply ]