Java邮件与土耳其字符的问题
我在使用 Java 代码发送的邮件中显示土耳其语字符时遇到问题。 这些字符在邮件中显示为问号 (?)。
Message msg = new MimeMessage(mailSession);
msg.setHeader("Content-Encoding","ISO-8859-9");
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject,"iso-8859-9");
msg.setSentDate(new Date());
msg.setContent(messageText, "text/html;ISO-8859-9");
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(mailSession);
msg.setHeader("Content-Encoding","ISO-8859-9");
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject,"iso-8859-9");
msg.setSentDate(new Date());
msg.setContent(messageText, "text/html;ISO-8859-9");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来 ISO-8859-9 应该能够处理您的土耳其字母。 文本是否有可能在其他地方使用错误的字符编码进行解码? 例如,如果电子邮件正文包含来自 Web 请求、另一封电子邮件或文件的文本,则此时可能指定了错误的解码器。
一种检查方法是打印
String
中 Unicode 代码点的数值:如果您看到
fffd
,那就是“替换字符”,意味着创建String
时使用的解码无法将字节(或字节序列)映射到字符。 如果您看到3f
,那是一个“?” 字符,并且意味着文本在更早的时候就被损坏了。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
:If you see
fffd
, that is the "replacement character" and means that the decoding used when theString
was created could not map a byte (or byte sequence) to a character. If you see3f
, that is a '?' character, and means that the text was corrupted even farther back.使用 UTF-8,这里有一个很好的编码概述:
http://www.joelonsoftware.com/articles/Unicode.html
Use UTF-8, here's a good overview of encoding:
http://www.joelonsoftware.com/articles/Unicode.html
您可以在这里找到解决方案:
http://www.serkankonakci.com/Project/wordpress/2009/02/04/java-mail-ile-mail-gonderme-ornegi/
即使使用此代码,您也可以通过附件或单个发送土耳其语邮件。
您还可以找到其他土耳其语字符集问题,只需在那里搜索即可。
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.