【发布时间】:2011-09-17 22:57:42
【问题描述】:
如何将使用 Apache Commons Email 生成的电子邮件的编码更改为 UTF-8?我想根据收件人的语言发送我生成的电子邮件,我需要考虑日语和俄语。问题是:Email 类没有提出我可以传递给Email.setCharset 方法的UTF-8 常量。有什么线索吗?
【问题讨论】:
标签: java email utf-8 apache-commons-email
如何将使用 Apache Commons Email 生成的电子邮件的编码更改为 UTF-8?我想根据收件人的语言发送我生成的电子邮件,我需要考虑日语和俄语。问题是:Email 类没有提出我可以传递给Email.setCharset 方法的UTF-8 常量。有什么线索吗?
【问题讨论】:
标签: java email utf-8 apache-commons-email
Apache Commons Email API 中似乎有一个 UTF_8 常量:
UTF_8
static final String UTF_8
See Also:
Constant Field Values
All Known Implementing Classes:
Email, HtmlEmail, ImageHtmlEmail, MultiPartEmail, SimpleEmail
在http://commons.apache.org/email/apidocs/src-html/org/apache/commons/mail/EmailConstants.html#line.38 中定义为:
String UTF_8 = "utf-8";
见http://commons.apache.org/email/apidocs/org/apache/commons/mail/EmailConstants.html
【讨论】:
如果您使用的是 1.2 版,您可以创建自己的常量,直到该方法接受一个字符串,如果 JVM 中不支持命名字符集,则会抛出 UnsupportedCharsetException。
如果可能,您可以在 Apache commons lang 的 CharEncoding 类中使用 UTF_8 常量。
【讨论】: