Search code examples
emailoutlookjakarta-mailemail-attachments

Outlook: problem with attachment in EML file generated by JavaMail


I have a problem opening emails with Outlook.

I am creating emails with JavaMail/JakartaMail API (version 1.6.x) in the rfc-email-format with the ending *.eml. Occasionally I have attachments with very long attachment names. JavaMail conforms to RFC2231 section 3: Parameter Value Continuations and splits long filenames (as far as my few oservations can tell) after 60 characters.

So a short attachment name looks something like this:

Content-Disposition: attachment;
    filename=short-filename.txt

and a long filename looks something like this:

Content-Disposition: attachment;
    filename*0=this-is-a-filename-with-more-than-60-characters-which-is-ult;
    filename*1=imately-the-source-of-this-question.txt

Now if I open this *.eml file in Outlook, the first filename is displayed as is, but for the second attachment the name is something like unknown attachment 00004.txt.

If I open the email in Mozilla Thunderbird, everything works like a charm.

So I wonder if this is a bug in Outlook that does not implement parameter value continuation of RFC2231?

Or maybe this is just a bug in JavaMail implementation and Thunderbird is as robust as it does not care about this potential bug in JavaMail?

And most importantly, is there a better solution that implementing email generation and all affected RFCs myself, to get this to work in Oultook?


Solution

  • I found an answer in an older SO question Seems like JavaMail's MimeBodyPart.setFileName inserts a line break in the email message and causes the filename to show up as invalid.

    Setting mail.mime.splitlongparameters to false works perfectly for me.