You must use one or two headers for each attachment:
If this is a normal attachment:
- Content-Disposition: attachment; file name = ...
If it is an embedded application (image for your mail)
- Content-Disposition: inline
- Content-ID: arbitrary-id
This is an extract for a small sending program that I programmed a while ago:
bodyPart is a MimeBodyPart .
bodyPart.setHeader("Content-Disposition", disp + "; filename=" + encodedFileName); bodyPart.setHeader("Content-Transfer-Encoding", "base64"); if (att.getContextId() != null && att.getContextId().length() > 0) bodyPart.setHeader("Content-ID", "<" + att.getContextId() + ">");
In it: disp has inline or attachment , and att.getContextId() has some arbitrary identifier for the attached attachment.
My recipe for HTML mail
message has via .setContent(...) mainMultipart is a MimeMultiPart("alternative") and has via .addBodyPart(...) textBodyPart is a MimeBodyPart with content-type "text/plain" relatedMultipart is a MimeMultipart("related") and has via .addBodyPart(...) htmlBodyPart "text/html; charset=utf-8" INLINED-ATTACH1 INLINED-ATTACH2 NORMAL-ATTACH1 NORMAL-ATTACH2
source share