Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accent support for mails in Spring Framework

I'm sending a mail with the word Òmnium (see the accent) in the sender using 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've tried two approaches:

  1. No handling to from
  2. Encode with : MimeUtility.encodeText(from) or MimeUtility.encodeText(from, "UTF-8", null)

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

What is the right approach?

like image 873
Llistes Sugra Avatar asked Jan 24 '26 03:01

Llistes Sugra


1 Answers

The second approach works fine. Note that you shouldn't apply MimeUtility.encodeText() to the address part of the From field, i. e.

String from = MimeUtility.encodeText("Òmnium", "UTF-8", null) + " <[email protected]>";
like image 85
axtavt Avatar answered Jan 25 '26 18:01

axtavt