1

My application sends out mail with attachment. Problem arises if the attached filename is more than 60 characters. Because in that scenario, the filename is automatically trimmed to 60 characters when the recipient sees the mail in outlook. When I printed the headers in my java code I can see that the filename (1234567890123456789012345678901234567890123456789012345678901234567890.txt) has been split into multiple parameters, slicing at the 60th character.

Content-Type: text/plain; charset=us-ascii; ^M
        name*0=123456789012345678901234567890123456789012345678901234567890; ^M
        name*1=1234567890.txt^M
Content-Transfer-Encoding: 7bit^M
Content-Disposition: attachment; ^M
        filename*0=123456789012345678901234567890123456789012345678901234567890; ^M
        filename*1=1234567890.txt^M

Somehow Outlook picks up only filename*0

I came across a post (https://docs.oracle.com/javaee/6/api/javax/mail/internet/package-summary.html) that said setting this property to false mail.mime.foldtext will help, but to no avail. Any pointers on this will be of great help

My java code snippet

MimeAttachment attachment = attachments[i];
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setDataHandler(new DataHandler(new MimeAttachmentDataSource(attachment)));
bodyPart.setFileName(attachment.getFilename());
bodyPart.setDisposition(MimeBodyPart.ATTACHMENT);

much thanks

Neo
  • 49
  • 12
  • 2
    Could you check with setting this parameter to false: `mail.mime.splitlongparameters`. – nourhero Aug 17 '20 at 18:18
  • Thank you but it didn't help. I used System.setProperty("mail.mime.splitlongparameters", "false"); – Neo Aug 17 '20 at 18:51
  • Is there a specific location in the code I should add it? – Neo Aug 17 '20 at 18:54
  • You can check at the link below: https://stackoverflow.com/questions/45196491/spring-mimemessagehelper-attachment-filename-encoding – nourhero Aug 18 '20 at 01:37
  • 1
    The system property `mail.mime.splitlongparameters` should have the expected effect. However, it is evaluated only once by javamail/Jakarta Mail upon loading class [`ParameterList`](https://github.com/eclipse-ee4j/mail/blob/342d86b928b7d390e879dc2d47eb897879946849/mail/src/main/java/jakarta/mail/internet/ParameterList.java#L132). As this class is referenced by other parts of javamail, it might be loaded earlier then expected so that setting the property via `System.setProperty()` might only happen afterwards. – Christoph Böhme Sep 03 '20 at 06:01
  • 1
    Also, see this answer: https://stackoverflow.com/a/53344141/8362098 – Christoph Böhme Sep 03 '20 at 07:25

0 Answers0