Naftuli Kay
Naftuli Kay

Reputation: 91620

Setting multiple content encodings in MimeMessage

When using javax.mail.*, I'm trying to send a message with the content encoded in both text/plain and text/html. How can I add both encodings to the MimeMessage?

Does setText override the previous text set? ie: if I do setText("", "text/plain") then setText("", "text/html"), will the secord call override the message text previously set or will they both be present in the message?

Upvotes: 0

Views: 1105

Answers (1)

ChrisG
ChrisG

Reputation: 2948

Q: How do I send mail with both plain text as well as HTML text so that each mail reader can choose the format appropriate for it?

A: You'll want to send a MIME multipart/alternative message. You construct such a message essentially the same way you construct a multipart/mixed message, using a MimeMultipart object constructed using new MimeMultipart("alternative"). You then insert the text/plain body part as the first part in the multpart and insert the text/html body part as the second part in the multipart. You'll need to construct the plain and html parts yourself to have appropriate content. See RFC2046 for details of the structure of such a message.

http://www.oracle.com/technetwork/java/faq-135477.html#sendmpa

Upvotes: 1

Related Questions