Java mail problem with Turkish characters

后端 未结 3 1392
灰色年华
灰色年华 2021-01-22 09:28

I have problem of showing Turkish characters in mail sent with Java code. The characters are shown as question marks (?) in mail.

Message msg = new MimeMessage(m         


        
相关标签:
3条回答
  • 2021-01-22 10:08

    It looks like ISO-8859-9 should be able to handle your Turkish letters alright. Is it possible that the text is decoded somewhere else with the wrong character encoding? For example, if the body of the email contains text from a web request, another email, or a file, perhaps the wrong decoder is specified at that point.

    One way to check would be to print the numeric value of the Unicode code points in the String:

    for (int idx = 0; idx < str.length(); ++idx) {
      System.out.println(Integer.toHexString(str.charAt(idx)));
    }
    

    If you see fffd, that is the "replacement character" and means that the decoding used when the String was created could not map a byte (or byte sequence) to a character. If you see 3f, that is a '?' character, and means that the text was corrupted even farther back.

    0 讨论(0)
  • 2021-01-22 10:08

    Use UTF-8, here's a good overview of encoding: http://www.joelonsoftware.com/articles/Unicode.html

    0 讨论(0)
  • 2021-01-22 10:17

    You can find the solution here:

    http://www.serkankonakci.com/Project/wordpress/2009/02/04/java-mail-ile-mail-gonderme-ornegi/

    even with this code, you can send with attachment or single mail in Turkish. And you can find other Turkish charset problem, just search there.

    0 讨论(0)
提交回复
热议问题