I am trying to send letters that may contain UTF-8 characters in the subject, message body and attachment file name.
I can send UTF-8 characters as part of the Subject as well as the body of the Mesage. However, when I send an attachment that has UTF-8 characters as the name of the attachment file, it does not display it correctly.
So my question is, how can I set the attachment file name as UTF-8?
Here is part of my code:
MimeBodyPart pdfPart = new MimeBodyPart(); pdfPart.setDataHandler(new DataHandler(ds)); pdfPart.setFileName(filename); mimeMultipart.addBodyPart(pdfPart);
Next edit:
I replaced
pdfPart.setFileName(filename);
from
pdfPart.setFileName(MimeUtility.encodeText(filename, "UTF-8", null));
and it works great. Thanks to everyone.
Tonia source share