Java 希伯来语中的Runnable JAR错误编码

Java 希伯来语中的Runnable JAR错误编码,java,eclipse,encoding,executable-jar,right-to-left,Java,Eclipse,Encoding,Executable Jar,Right To Left,我创建了一个用希伯来语发送电子邮件的java应用程序 当我通过Eclipse运行它时,一切都很好 但是, 当我通过导出的Runnable JAR文件运行它时,一切都不再正常 当我在outlook上收到邮件时,它是完美的: 第19课:2014-09-16课:13:00:24课 העבוהה: 但是,当我在Gmail上收到信息时,一切都乱七八糟: מ§§××:19ד×××קה×לה:2014-09-16דה××××××××××××××”:13:00:24××) הפרוי×

我创建了一个用希伯来语发送电子邮件的java应用程序

当我通过Eclipse运行它时,一切都很好

但是,

当我通过导出的Runnable JAR文件运行它时,一切都不再正常

当我在outlook上收到邮件时,它是完美的:

第19课:2014-09-16课:13:00:24课 העבוהה:

但是,当我在Gmail上收到信息时,一切都乱七八糟:

מ§§××:19ד×××קה×לה:2014-09-16דה××××××××××××××”:13:00:24××) הפרוייקט: ×©× ×ž×–×ž×™×ד××、הודה:


我试着使用浏览器的编码设置,但运气不好,现在设置为Unicode UTF 8。我在eclipse中的项目设置为UTF-8。

我终于让它开始工作了

使用此代码:

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

您的电子邮件是否是Java应用程序在发送之前读取的文本文件?您是否从控制台运行独立Java应用程序?您使用的是什么操作系统?电子邮件是根据输入到应用程序的文本创建的,它是用户填写的一种表单类型,之后我通过邮件发送数据。我通过双击运行runnable jar,而不是控制台,我使用Win7 Pro x64。当Gmail阅读邮件时,您可以检查电子邮件中使用的字符集,并尝试查找类似内容类型的内容:text/plain;字符集=UTF-8。如果字符集不是UTF-8,那么您的Java应用程序一定有问题,可能是使用了一些默认字符集而不是UTF-8•וארMeimad MTVS Studio,这很奇怪,字符集是UTF-8,但它应该是ISO-8859-1,这就是我从Java输出它的方式。