{"id":397,"date":"2012-01-31T21:50:56","date_gmt":"2012-01-31T21:50:56","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=397"},"modified":"2012-01-31T22:51:18","modified_gmt":"2012-01-31T22:51:18","slug":"internationalization-issues-how-to-set-utf-8-with-mimemessage-for-email-in-java","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2012\/01\/31\/internationalization-issues-how-to-set-utf-8-with-mimemessage-for-email-in-java\/","title":{"rendered":"Internationalization issues: How to set UTF-8 with MimeMessage for email in Java"},"content":{"rendered":"<p>Content and subject for Chinese, Japanese, Korean (CJK) and other language characters showing up garbled or with question marks ????<\/p>\n<p>Gosh! I know &#8211; What a pain! But, there&#8217;s a solution! Simply set the encoding to UTF-8 and not ISO8859_1 or any other encoding format.<\/p>\n<p>Found a <a href=\"http:\/\/www.isocra.com\/2006\/11\/utf-8-subjects-in-javaxmail\/\">good post from Isocra Consulting<\/a> that solves this issue.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nProperties props = new Properties();\r\n\/\/ put in your SMTP host in here\r\nprops.put(&quot;mail.smtp.host&quot;, &quot;localhost&quot;);\r\nSession s = Session.getInstance(props, null);\r\n\r\nMimeMessage message = new MimeMessage(s);\r\nmessage.setFrom(new InternetAddress(from));\r\nmessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));\r\nmessage.setHeader(&quot;Content-Type&quot;, &quot;text\/plain; charset=UTF-8&quot;);\r\nmessage.setSubject(subject, &quot;UTF-8&quot;); \/\/IMPORTANT\r\n\r\n\/\/ Either use setText() or setContent()\r\nmessage.setText(body, &quot;UTF-8&quot;); \/\/IMPORTANT \r\n\/\/ message.setContent(body, &quot;text\/plain; charset=UTF-8&quot;); \/\/ ALTERNATIVELY USE THIS\r\n\r\nTransport.send(message);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Content and subject for Chinese, Japanese, Korean (CJK) and other language characters showing up garbled or with question marks ???? Gosh! I know &#8211; What a pain! But, there&#8217;s a solution! Simply set the encoding to UTF-8 and not ISO8859_1 or any other encoding format. Found a good post from Isocra Consulting that solves this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/397"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=397"}],"version-history":[{"count":5,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":400,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/397\/revisions\/400"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}