Frage

I have this code, which sends activation email to user:

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();
}

However when I read it on my Android Gmail client, polish chars are encoded incorrectly.

I've checked:

  • Android studio encoding settings, and set all to UTF-8
  • ResourceBundle file encoding, which is UTF-8 aswell
War es hilfreich?

Lösung 2

Just changing properties files encoding in Android Studio was not enough. I have to delete the problematic file and create it from scratch.

Andere Tipps

I'd suggest directly setting the language via htmlPart.setContentLanguage()

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top