Java 通过GAE向用户发送UTF-8编码的电子邮件和编码错误的字符

Java 通过GAE向用户发送UTF-8编码的电子邮件和编码错误的字符,java,google-app-engine,android-studio,Java,Google App Engine,Android Studio,我有这个代码,它向用户发送激活电子邮件: public static void sendActivationEmail(User user) throws Exception { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); ResourceBundle bundle = ResourceBundle.getBundle("pl

我有这个代码,它向用户发送激活电子邮件:

public static void sendActivationEmail(User user) throws Exception {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    ResourceBundle bundle = ResourceBundle.getBundle("pl/hello/hello/resources/bundle", user.getLocale());

    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(AaGAEAppTools.getAdminEmail(), "Hello"));
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail(), user.getName()));
    msg.setSubject(bundle.getString("activation.email.title"));

    Multipart mp = new MimeMultipart();
    MimeBodyPart htmlPart = new MimeBodyPart();
    htmlPart.setContent(getActivationEmailHtml(user), "text/html; charset=utf-8");
    mp.addBodyPart(htmlPart);
    msg.setContent(mp);

    Transport.send(msg);
}

public static String getActivationEmailHtml(User user) throws Exception {
    Locale locale = user.getLocale();
    ResourceBundle b = ResourceBundle.getBundle("pl/aprilapps/gameofwords/resources/bundle", locale);
    InputStream is = new FileInputStream("WEB-INF/emails/activation_template.html");
    StringWriter writer = new StringWriter();
    IOUtils.copy(is, writer, "UTF-8");
    return writer.toString();
}
然而,当我在Android Gmail客户端上阅读它时,波兰字符的编码是错误的

我查过:

  • Android studio编码设置,并将全部设置为UTF-8
  • ResourceBundle文件编码,也是UTF-8

我建议通过htmlPart.setContentLanguage()直接设置语言。

仅仅在Android Studio中更改属性文件编码是不够的。我必须删除有问题的文件并从头开始创建。

我建议您使用freemarker模板库为appengine发送模板电子邮件,因为它非常灵活且易于使用。您也可以使用它作为参考。使用freemaker库,但问题似乎出在从ResourceBundle注入的内容中,该内容仍然显示不正确。您在.ftl文件中添加了此内容。