{"id":239,"date":"2005-02-25T13:18:37","date_gmt":"2005-02-25T19:18:37","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=239"},"modified":"2015-06-12T21:15:45","modified_gmt":"2015-06-13T03:15:45","slug":"setting-the-content-encoding-for-html-message-parts-with-javamail","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/239","title":{"rendered":"Setting the content encoding for HTML message parts with Javamail"},"content":{"rendered":"<p>I spent an hour chasing down the solution to this issue, so I figured I&#8217;d post it (or at least what worked for me).  Basically, I have a multi-part message that can have different content encodings for each text part.  I want to send this message via <a href='http:\/\/java.sun.com\/products\/javamail\/'>javamail<\/a>.  Now, there&#8217;s support for <a href='http:\/\/java.sun.com\/products\/javamail\/javadocs\/javax\/mail\/internet\/MimeBodyPart.html#setText(java.lang.String,%20java.lang.String)'>setting content as type &#8216;text\/plain&#8217; with a different character set<\/a>, but if you want to add a part that is a different subtype of text to your message, there is no convenience method.  However, <a href='http:\/\/archives.java.sun.com\/cgi-bin\/wa?A2=ind0402&amp;L=javamail-interest&amp;F=&amp;S=&amp;P=3824'>this mail message<\/a> had an example of how to specify html content and a character set: <\/p>\n<p><code>MimeBodyPart htmltext = new MimeBodyPart();<br \/>\nhtmltext.setContent(someDanishChars, \"text\/html; charset=\\\"ISO-8859-1\\\"\"); <\/code><\/p>\n<p>(The author had some issues with this method in different app servers; it works fine for me in a stand alone java program.)<\/p>\n<p>These additional parameters to the &#8216;Content-Type&#8217; header are laid out, for text documents, in section 4.1 of <a href='http:\/\/www.tac.nyc.ny.us\/cgi-bin\/rfc?2046'>RFC 2046<\/a>.  Here&#8217;s a collection of helpful <a href='http:\/\/www.tac.nyc.ny.us\/mail\/rfc-index.html'>email related RFCs<\/a>. Additionally, section 5.1 of <a href='http:\/\/www.tac.nyc.ny.us\/cgi-bin\/rfc?2045'>RFC 2045<\/a> outlines the way to add parameters and gives examples of the charset parameters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent an hour chasing down the solution to this issue, so I figured I&#8217;d post it (or at least what worked for me). Basically, I have a multi-part message [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-java","category-programming"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":1,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":2072,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/239\/revisions\/2072"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}