Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Attachments in a "multipart/alternative" message

843830Nov 5 2002 — edited Jan 28 2010
Hello,

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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 25 2010
Added on Nov 5 2002
12 comments
1,680 views