Java 附件+;使用commons电子邮件生成的Html不';在一些电子邮件客户端中不显示
一段时间以来,我一直在使用apachecommons邮件中的org.apache.commons.mail.HtmlEmail类。最终,一些用户抱怨说,他们的电子邮件客户端上显示的电子邮件没有附件(Outlook2007和LotusNotes中报告了这个问题) 一位用户甚至分析了问题,并向我发送了以下链接: 我已经读到,由于这个问题,其他人已经切换到raw javax.mailapi 下面是附加文件的代码部分:Java 附件+;使用commons电子邮件生成的Html不';在一些电子邮件客户端中不显示,java,email,html-email,apache-commons-email,Java,Email,Html Email,Apache Commons Email,一段时间以来,我一直在使用apachecommons邮件中的org.apache.commons.mail.HtmlEmail类。最终,一些用户抱怨说,他们的电子邮件客户端上显示的电子邮件没有附件(Outlook2007和LotusNotes中报告了这个问题) 一位用户甚至分析了问题,并向我发送了以下链接: 我已经读到,由于这个问题,其他人已经切换到raw javax.mailapi 下面是附加文件的代码部分: private void dummy(List<Map<String,
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
}
private void dummy(列表附件,字符串htmlText)引发EmailException{
HtmlEmail memail;
memail=新的HtmlEmail();
memail.setHtmlMsg(htmlText);
setextmsg(“您的邮件客户端无法识别HTML电子邮件。”);
迭代器iter=attachments.Iterator();
while(iter.hasNext()){
Map=iter.next();
Set entries=map.entrySet();
对于(条目:条目){
试一试{
ByteArrayDataSource bads=新的ByteArrayDataSource(
entry.getValue(),null);
embed(bads,entry.getKey());
//memail.attach(bads,entry.getKey(),“”);//如果我使用它,html消息
//流离失所
}捕获(IOE异常){
抛出新的EmailException(e);
}
}
}
//…继续
}
以前有人经历过吗
先谢谢你
Jonathas看来commons电子邮件版本1.1存在问题。升级到1.2似乎可以解决这个问题