1

一段时间以来,我一直在使用来自 apache commons-mail 的 org.apache.commons.mail.HtmlEmail 类。最终,一些用户抱怨他们的电子邮件客户端上显示的电子邮件没有附件(Outlook 2007 和 Lotus Notes 中报告了此问题)。

一位用户甚至分析了问题并向我发送了以下链接:

http://support.microsoft.com/kb/961940

我读过其他人:由于这个问题,已经切换到原始 javax.mail API。

这是附加文件的代码部分:

private void dummy(List<Map<String, byte[]>> attachments, String htmlText) throws EmailException {
    HtmlEmail memail;

    memail = new HtmlEmail();
    memail.setHtmlMsg(htmlText);
    memail.setTextMsg("Your mail client doesn't recognize HTML e-mails.");

    Iterator<Map<String, byte[]>> iter = attachments.iterator();
    while (iter.hasNext()) {
        Map<java.lang.String, byte[]> map = iter.next();

        Set<Entry<String, byte[]>> entries = map.entrySet();
        for (Entry<String, byte[]> entry : entries) {
            try {
                ByteArrayDataSource bads = new ByteArrayDataSource(
                        entry.getValue(), null);
                memail.embed(bads, entry.getKey());
//              memail.attach(bads, entry.getKey(), ""); // if I use this, the html message 
                        // gets displaced
            } catch (IOException e) {
                throw new EmailException(e);
            }
        }
    }
    // ... continues
}

以前有人经历过吗?

提前非常感谢。

乔纳萨斯

4

1 回答 1

2

commons-email 1.1 版似乎有问题。升级到 1.2 似乎可以解决问题。

于 2009-11-30T19:29:45.113 回答