views:

39

answers:

2

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:

HtmlEmail 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.

+1  A: 

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

pstanton
A: 

did you try this?

email.attach(bads, "files.zip", "files", EmailAttachment.ATTACHMENT);
Aaron Saunders
this is already done by the library if you leave it out.
pstanton