Accent support for email messages in the Spring Framework

I am sending mail with the word Òmnium (see emphasis) in the sender using the Spring Framework.

The code is the one I found for Spring:

    org.springframework.mail.javamail.JavaMailSenderImpl sender = sender();
    javax.mail.internet.MimeMessage msg = sender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(msg, multipart, "UTF-8");
    helper.setFrom(from);
    ...
    sender.send(msg);

I tried two approaches:

  • Disclaimer
  • Encode with: MimeUtility.encodeText(from)orMimeUtility.encodeText(from, "UTF-8", null)

The first case gives me a question mark. The second gives =?UTF-8?Q?=C3=92mnium, as seen in Thunderbird.

What is the right approach?

+3
source share
1 answer

The second approach works fine. Please note that you should not apply MimeUtility.encodeText()to the address part of the field From, i. e.

String from = MimeUtility.encodeText("Òmnium", "UTF-8", null) + " <test@test.com>";
+3
source

Source: https://habr.com/ru/post/1751433/


All Articles