电子邮件Java邮件编码非英语字符
使用下面的代码,我可以发送一封用非英语书写的电子邮件,尽管主题看起来正确,但正文看起来像胡言乱语
有什么想法吗
多谢各位
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);
}
# 1 楼答案
如果没有其他帮助,请尝试将源文件(包括.java文件)的编码更改为UTF8。 在Eclipse中,它是通过窗口完成的->;偏好->;一般->;工作空间:文本文件编码 我的文本文件默认使用CP1252
我收到了我的短信。属性文件。把它们改成UTF8也没用。 这太疯狂了,但我改变了主意。java文件到UTF8解决了我的问题
# 2 楼答案
试试看:
编辑更改为^{
# 3 楼答案
而不是
我会写
我从你的名字中猜到了
ISO-8859-7
,因为这个字符集是希腊语的,但也许你可以更恰当地选择它。或者UTF-8
也适用于你的情况