简体   繁体   中英

Apache Commons Email, how to email attachment with Content-Transfer-Type as quoted-printable?

I have an app that talks to someone else's server by sending emails with attachments.

I used Apache Commons Email to send the email with attachment like so:

MultiPartEmail email = new MultiPartEmail();
email.setHostName(sHostName);
email.addTo("bob@bob.com");
email.addFrom("andy@andy.com");
email.setSubject("the subject");
email.setMsg("the message");

byte[] documentFile = /* ... */;
String filename = "my file.pdf";
String description = "this is my file";

email.attach(new ByteArrayDataSource(myPDF, "application/pdf"), filename, description, EmailAttachment.ATTACHMENT);

email.send();

The problem is, the guy at the other end says "the header info has a Content-Transfer-Encoding value of "7bit" and it needs to be "quoted-printable".

My question is, how do I make this change so the file is attached in the appropriate way?

Rob

Commons email decides based on the content of the attachment which encoding to use, see http://thecarlhall.wordpress.com/2010/09/01/setting-quoted-printable-in-a-commons-email-body-part/ for some related discussion. Also the underlying java-mail seems to do this automatically according to the javadoc .

The blog-post states that you can try to use

email.addHeader("Content-transfer-encoding", "quoted-printable");

but it may corrupt other parts of the mail as a result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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