Thursday, January 13, 2011

Display Chinese Characters in Gmail

As some of my clients from china, they want to save Chinese characters in database and retrieve it in web page. It is a piece of cake to save and display those characters in web page.


To save Chinese character in database:


Insert into Table1 ( Field1, Field2) values ( Test1 , N'藏青')


But there is a function to send system generated email to customers. Here is the problem !!! I am very strange that the Chinese characters cannot display both of my gmail and outlook . There is ?????-???? instead of displaying Chinese characters. So I research online and I found some code from codeproject website that can able to see Chinese characters in Gmail. See the following code:


public string getCorrectCharacter(string str)
{
       Encoding iso = Encoding.GetEncoding("iso8859-1");
       Encoding unicode = Encoding.UTF8;
       byte[] unicodeBytes = unicode.GetBytes(str);
       return iso.GetString(unicodeBytes);
}

Although Gmail can display chinese character correctly, Outlook Email still cannot display. I will continue to find to display correctly in every email.

If you guys have the code, please share to me. Thanks in advance

2 comments:

  1. Yay.. I found the solution to display chinese characters in Outlook Email.

    Pls add the following code in your email function.

    message.BodyFormat = MailFormat.Html;
    message.BodyEncoding = Encoding.UTF8;

    Finally, you can see chinese characters in whatever email.

    Thank you very much.

    ReplyDelete
  2. hi, do you have a JAVA code for this?

    ReplyDelete

If this post is useful, pls comment here.