Java邮件编码非英文字符
-
23-09-2019 - |
题
使用代码下面我可以发送写入非英语和虽然受试者正确显示全身出现为乱码的电子邮件。结果 任何想法?点击 谢谢
public void postMail(String recipient, String subject, String message, String from) throws MessagingException, UnsupportedEncodingException {
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "mail.infodim.gr");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress addressTo=new InternetAddress(recipient);
msg.setRecipient(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
没有正确的解决方案
其他提示
尝试:
msg.setContent(message, "text/plain; charset=UTF-8");
修改强>改为text/plain
。
代替
msg.setContent(message, "text/plain");
我会写
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(message, "text/plain; charset=ISO-8859-7");
mp.addBodyPart(mbp);
msg.setContent(mp);
我猜ISO-8859-7
从你的名字,因为这个,charset是希腊,但也许你可以更准确地选择它。或者,也许还UTF-8
作品的情况。
如果没有其他帮助,请尝试更改源文件的编码(包括.java文件)到UTF8。 在Eclipse中它是通过窗口进行 - >首选项 - >常规 - >工作空间:文本文件编码 我有CP1252作为我的文本文件默认的。
我收到来自.properties文件我的文字。他们更改为UTF8没有帮助。 这是疯了,但我的切换.java文件到UTF8解决了我的问题!
不隶属于 StackOverflow