[英]Runnable JAR bad Encoding in hebrew
I created a java app that send email in Hebrew. 我创建了一个Java应用程序,可以使用希伯来语发送电子邮件。
When I run it via Eclipse, everything is fine , 当我通过Eclipse运行它时,一切都很好 ,
BUT, 但,
When I run it via The exported Runnable JAR file everything is not fine anymore! 当我通过导出的Runnable JAR文件运行它时,一切都变糟了!
When I receive the message on outlook its perfect: 当我收到有关Outlook的消息时,它是完美的:
מק"ט: 19 התקבל ב: 2014-09-16 בשעה: 13:00:24 שם הפרוייקט: שם מזמין העבודה:
区域:19区域:2014-09-16区域:13:00:24区域:区域区域:
BUT, When I receive the massage on Gmail, it's all scrambled: 但是, 当我在Gmail上收到消息时,一切都变得混乱了:
מק"ט: 19 התק×'ל ×': 2014-09-16 ×'שעה: 13:00:24 ×©× ×”×¤×¨×•×™×™×§×˜: ×©× ×ž×–×ž×™×Ÿ ×”×¢×'ודה:
מק“×〜:19התק×'ל×':2014-09-16×'שעה:13:00:24ש×הפר וייק×〜:ש×מזמיןהע×'ודה:
I tried to play with the browsers encoding settings, but no such luck, It's now set to Unicode-UTF 8. My project in eclipse is set to UTF-8. 我尝试使用浏览器的编码设置,但是没有运气,现在将其设置为Unicode-UTF8。我在eclipse中的项目设置为UTF-8。
i finally got it to work, 我终于让它工作了,
used this code: 使用此代码:
// -- Create a new message --
final MimeMessage msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(username));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail, false));
if (ccEmail.length() > 0) {
msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(ccEmail, false));
}
msg.setSubject(title, "utf-8");
msg.setText(message, "utf-8");
msg.setHeader("Content-Type", "text/html; charset=UTF-8");
msg.setSentDate(new Date());
MimeBodyPart mbp1 = new MimeBodyPart();
try {
mbp1.setDataHandler(new DataHandler(
new ByteArrayDataSource(message.toString(), "text/html")));
} catch (IOException e1) {
e1.printStackTrace();
}
mbp1.setHeader("Content-Type","text/plain; charset=\"utf-8\"");
mbp1.setContent( message, "text/html; charset=utf-8" );
mbp1.setHeader("Content-Transfer-Encoding", "quoted-printable");
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
try {
mbp2.attachFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp, "text/html");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.