commons-emailで生成されたAttachments + Htmlが一部のメールクライアントで表示されない
-
10-07-2019 - |
質問
しばらくの間、apache commons-mailのorg.apache.commons.mail.HtmlEmailクラスを使用していました。最終的に、一部のユーザーは、電子メールクライアントに電子メールが添付されずに表示されることを訴えます(Outlook 2007およびLotus Notesで報告された問題)。
1人のユーザーが問題を分析し、次のリンクを送ってくれました:
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
}
以前にそれを経験したことがありますか?
事前に感謝します。
ジョナタ
解決
commons-emailバージョン1.1に問題があったようです。 1.2にアップグレードすると問題が解決するようです。
所属していません StackOverflow