【问题标题】:Apache Commons Email and UTF-8Apache Commons 电子邮件和 UTF-8
【发布时间】:2011-09-17 22:57:42
【问题描述】:

如何将使用 Apache Commons Email 生成的电子邮件的编码更改为 UTF-8?我想根据收件人的语言发送我生成的电子邮件,我需要考虑日语和俄语。问题是:Email 类没有提出我可以传递给Email.setCharset 方法的UTF-8 常量。有什么线索吗?

【问题讨论】:

    标签: java email utf-8 apache-commons-email


    【解决方案1】:

    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

    【讨论】:

    • 您是否尝试过设置字符串值而不是引用常量?
    【解决方案2】:

    如果您使用的是 1.2 版,您可以创建自己的常量,直到该方法接受一个字符串,如果 JVM 中不支持命名字符集,则会抛出 UnsupportedCharsetException。

    如果可能,您可以在 Apache commons lang 的 CharEncoding 类中使用 UTF_8 常量。

    【讨论】:

      猜你喜欢
      • 2011-10-05
      • 2018-09-22
      • 1970-01-01
      • 2011-02-04
      • 2023-04-08
      • 2018-11-17
      • 1970-01-01
      • 2012-04-24
      • 2013-11-14
      相关资源
      最近更新 更多