Java邮件问题与土耳其字符 [英] Java mail problem with Turkish characters

查看:180
本文介绍了Java邮件问题与土耳其字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在使用Java代码发送的邮件中显示土耳其字符的问题。这些字符在邮件中显示为问号(?)。

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");


推荐答案

看起来ISO-8859-9以处理您的土耳其字母。是否有可能文本被解码的其他地方有错误的字符编码?例如,如果电子邮件的正文包含来自网络请求,其他电子邮件或文件的文本,则可能在此时指定了错误的解码器。

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.

单向检查是否会在 String

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

如果您看到 fffd ,即替换字符,意味着创建 String 时使用的解码无法将字节(或字节序列)映射到字符。如果您看到 3f ,那是一个'?'字符,表示文本已损坏,甚至更远。

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.

这篇关于Java邮件问题与土耳其字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆