By pstanton


2010-09-21 02:02:57 8 Comments

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.

2 comments

@pstanton 2010-09-21 02:46:11

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

@Aaron Saunders 2010-09-21 02:50:27

did you try this?

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

Related Questions

Sponsored Content

25 Answered Questions

[SOLVED] Sending Email in Android using JavaMail API without using the default/built-in app

6 Answered Questions

[SOLVED] How to attach a file to an HTML email using Apache Commons Email

1 Answered Questions

2 Answered Questions

1 Answered Questions

Display a functional <a> link in an email?

1 Answered Questions

HtmlEmail not rendering HTML correctly (apache commons)

1 Answered Questions

Sponsored Content