Attachments in a "multipart/alternative" message
843830Nov 5 2002 — edited Jan 28 2010Hello,
I am having some problems with including attachments. I have followed the instructions provided in http://developer.java.sun.com/developer/qow/archive/74/ which work well for simple emails. However, I am trying to construct emails with multiple "parts" (eg, text and html and attachments).
If I follow the attachment example listed above, I would create my MimeMultipart with a parameterless constructor as follows:
MimeMultipart mp = new MimeMultipart();
According to the JavaMail documenation, this creates a "multipart/mixed" message by default. This is fine, and the attachment is included in the message as expected. However, because I am creating multiple parts (with different content-types), I also get my HTML part as an attachment!
I can fix this but using the alternative constructor for the MimeMultipart, and by creating a "multipart/alternative" message as follows:
MimeMultipart mp = new MimeMultipart("alternative");
... This gives me (what appears to be) the correct structure, ie I have a text part and an HTML part, but I lose my attachment!
When I create an email manually using (for example) Microsoft Outlook Express, it seems to create a "multipart/mixed" email, which contains a "multipart/alternative" part, which in turn contains the text and html parts. I am fairly sure this is what I need to do, but I am not sure how to do it with JavaMail.
Any ideas?