Spring MimeMessageHelper attachment filename encoding

Viewed 5314

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
4 Answers

Add this line before MimeMessageHelper instantiation:

System.setProperty("mail.mime.splitlongparameters", "false");

Had the same problem with Japanese file name and the following steps fixed it,

MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,  MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED, "UTF-8");
//IMP steps
System.setProperty("mail.mime.splitlongparameters", "false");
attachedFileName = MimeUtility.encodeText(attachedFileName, "UTF-8", "Q");
//
helper.addAttachment(attachedFileName, attachmentFile);

The Mimeutility.encodetext without the Q option did not work nor did it work without setting the system.setproperty. This tells the mimeutility to encode the string in a quoted-printable - Found something here - https://stackoverflow.com/a/21575089

Related