1

私はしばらくの間、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
}

誰もそれを経験したことがありますか?

よろしくお願いします。

ジョナタス

4

1 に答える 1

2

commons-email バージョン 1.1 に問題があったようです。1.2 にアップグレードすると問題が解決するようです。

于 2009-11-30T19:29:45.113 に答える