How do I use JavaMail API to send multipart/alternative mails? I want to send an html-mail, but if the recipiant dont know how to parse them, they will see a text/plain version.

Andrea Pompili

You have to build the message using a MimeMultipart object as content.
If you have attachments you have to set the first part of the message with a MimeMultipart object .

To build a multipart/alternative object with a plain content and an html one follow this code:

String plain_text = ... ;
String html_text  = ... ;
MimeMultipart content = new MimeMultipart("alternative");
MimeBodyPart text = new MimeBodyPart();
MimeBodyPart html = new MimeBodyPart();
html.setContent(html_text, "text/html");
To parse a message with a content multipart/alternative you have to use the MimeMultipart class and then choose from the parts inside the one you prefer according to its content type.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact