I am sending mail with MimeMessageHelper
in my Spring Boot application.
How can I tell it to encode the filename, which contains the letter à
, so that it would display correctly?
Setting the encoding to UTF-8
when constructing MimeMessageHelper
does not seem to help. In Gmail, the resulting attachment is displayed as
=?UTF-8?Q?ex-comp_s.=C3=A0_r.l.?= =?UTF-8?Q?-201\"; filename*1=\"7-07-12_=E2=80=95_2017-07-18
I've solved the the problem with these lines:
System.setProperty("mail.mime.splitlongparameters", "false")
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8")
MimeUtility.encodeWord(attachmentFilename)
Here is the example code,
System.setProperty("mail.mime.splitlongparameters", "false");
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
// Your email content
helper.setFrom("...");
helper.setTo("...");
helper.setSubject("...");
helper.setText("...");
helper.addAttachment(
MimeUtility.encodeWord(attachmentFilename),
attachmentContent
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With