Apache Commons Email and UTF-8

笑着哭i 提交于 2019-12-08 15:59:07

问题


How do you change the encoding of an email generated with Apache Commons Email to UTF-8? I want to send emails I generate depending on the receiver's language, and I need to take in account Japanese and Russian. Problem is: the Email class doesn't propose a UTF-8 constant I can pass to the Email.setCharset method. Any clue?


回答1:


There does appear to be a constant for UTF_8 in the Apache Commons Email API:

UTF_8

static final String UTF_8
See Also:
  Constant Field Values

All Known Implementing Classes:
  Email, HtmlEmail, ImageHtmlEmail, MultiPartEmail, SimpleEmail

Which is defined in http://commons.apache.org/email/apidocs/src-html/org/apache/commons/mail/EmailConstants.html#line.38 as:

String UTF_8 = "utf-8";

See http://commons.apache.org/email/apidocs/org/apache/commons/mail/EmailConstants.html




回答2:


If you work with the version 1.2, you can create your own constant, until the method accept a String and will throw an UnsupportedCharsetException if there's no support for the named charset in the JVM.

If it's possible, you can use instead the UTF_8 constant in the CharEncoding class in Apache commons lang.



来源:https://stackoverflow.com/questions/6399187/apache-commons-email-and-utf-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!