Skip to content Skip to sidebar Skip to footer

Best Practices - Sending Javamail Mime Multipart Emails - And Gmail

I have a Tomcat application that needs to send confirmation emails etc. I have coded the emailer with Javamail (mail.jar) to send multipart text/html emails. I based the code on th

Solution 1:

Solved! It seems according to the multipart MIME spec, the order of the parts are important. They should be added in order from low fidelity to high fidelity. So it seems GMail follows the spec and uses the last part. In my case I had them HTML, Text. I just swapped the order to Text, HTML and Gmail renders it correctly...

i.e.

MimeBodyParttextPart=newMimeBodyPart();
textPart.setText(text, "utf-8");

MimeBodyParthtmlPart=newMimeBodyPart();
htmlPart.setContent(html, "text/html; charset=utf-8");

multiPart.addBodyPart(textPart); // <-- first
multiPart.addBodyPart(htmlPart); // <-- second
message.setContent(multiPart);

Thanks for the help!

Post a Comment for "Best Practices - Sending Javamail Mime Multipart Emails - And Gmail"