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,
I had a similar issue with cyrillic filenames for download. The solution is to encode filename (rfc5987):
and use it this way:
I found this solution here: http://outofrange.ru/2016/11/encode-non-ascii-filename-content-disposition/