简体   繁体   English

带附件的HTML电子邮件

[英]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 . 我正在尝试使用apache-commons-email 1.1在电子邮件中包含带有一些html内容的zip附件。

If i use this code, which sends an email without an attachment, the html body displays correctly. 如果我使用此代码发送没有附件的电子邮件,则html正文显示正确。

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: 但是使用以下内容,电子邮件正文是空白的,并且有一个名为“Part 1.2”的html附件(与我的zip附件一起)包含应该是电子邮件正文的内容:

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. ps我试图升级到commons-email 1.2但maven因为某些原因从refractions.net下载它。

确认:这是commons-email 1.1的一个问题,它在1.2中修复。

你试过这个吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM