开发者

html email with attachment

I'm attempting to include a zip attachment with some html content in an email using apache-commons-email 1.1.

If i use this code, which sends an email without an attachment, the html body displays correctly.

HtmlEmail email = new HtmlEmail();
email.setMailSession(mailSession);
email.setSubject(subject);
email.addTo(to);
email.setFrom(from);
email.setHtmlMsg(body);
email.send();

however using the following, the email body is blank, and there is an html attachment (alongside my zip attachment) called "Part 1.2" containing what is supposed to be the email body:

Ht开发者_JS百科mlEmail email = new HtmlEmail();
email.setMailSession(mailSession);
email.setSubject(subject);
email.addTo(to);
email.setFrom(from);
email.setHtmlMsg(body);
ByteArrayDataSource bads = new ByteArrayDataSource(zip, "application/zip");
email.attach(bads, "files.zip", "files");
email.send();

what can i do to avoid this problem?

ps i've tried to upgrade to commons-email 1.2 but maven breaks downloading it from refractions.net for some reason.


CONFIRMED: this is a problem with commons-email 1.1 and it is fixed in 1.2.


did you try this?

email.attach(bads, "files.zip", "files", EmailAttachment.ATTACHMENT);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜