【发布时间】:2009-11-30 18:20:05
【问题描述】:
一段时间以来,我一直在使用来自 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
}
以前有人经历过吗?
非常感谢。
乔纳塔斯
【问题讨论】:
标签: java email html-email apache-commons-email