My application has to send a textfile, which it first has to generate as a String. The text contains non-ASCII symbols, so i would like it to be UTF-8. I\'ve tried a lot of vari
I used to try send file name in url encoded. And it works for gmail
messageBodyPart.setFileName(UriUtils.encodePath(attachment.getAttachmentName(), "UTF-8"))
full code here:
if (!CollectionUtils.isEmpty(requestMessage.getAttachments())) {
MimeBodyPart messageBodyPart;
String fileName;
File file;
for (Attachment attachment : requestMessage.getAttachments()) {
messageBodyPart = new MimeBodyPart();
fileName = attachment.getAttachmentName();
file = new File(fileName);
FileUtils.writeByteArrayToFile(file, attachment.getAttachment());
messageBodyPart.setDataHandler(new DataHandler(new FileDataSource(file)));
messageBodyPart.setFileName(UriUtils.encodePath(attachment.getAttachmentName(), "UTF-8"));
messageBodyPart.setDisposition(Part.ATTACHMENT);
multipart.addBodyPart(messageBodyPart);
}
}