Why Clydesdale?
Expertise
Strategic Partners
Blog
Contact
Home
Clydesdale Software Logo

Clydesdale Software, Inc.

355 South Teller St.

Suite 200

Lakewood, CO 80226

info@ClydesdaleSoftware.com


Follow Us: Twitter RSS



Go Back

Japanese Email Encoding

If you are going to be sending emails to Japan you need to use iso-2022-jp encoding for the body and subject.  This does not mean you have to store information in this format as the encoding can be done before the email is sent in code.

 

Here is a quick example of how this can be done.

  582 var japeneseEncoding = Encoding.GetEncoding(LanguageEncodingConstants.JapaneseEncoding);

  583 

  584 // Encode Body

  585 message.Body = LanguageEncodeString(message.Body, japeneseEncoding);

  586 message.BodyEncoding = japeneseEncoding;

  587 

  588 // Encode subject

  589 message.Subject = LanguageEncodeString(message.Subject, japeneseEncoding);

  590 message.SubjectEncoding = japeneseEncoding;

Note in the above that the body and subject encoding on the message is also set.

And the method that does the encoding.

  597 private static string LanguageEncodeString(string stringToEncode, Encoding newEncoding)

  598 {

  599     var stringBytes = Encoding.UTF8.GetBytes(stringToEncode);

  600     var translatedBytes = Encoding.Convert(Encoding.UTF8, newEncoding, stringBytes);

  601 

  602     var translatedString = newEncoding.GetString(translatedBytes);

  603 

  604     return translatedString;

  605 }

Facebook Twitter DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Add diigo bookmark