3

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

centic
  • 15,565
  • 9
  • 68
  • 125
  • I have the same problem! Stange thing is, depending on the machine / OS where the mail is sent from, the Content-transfer-encoding is different! I'm going to use HtmlMail instead and see the result. – marcolopes Jun 07 '17 at 20:12

1 Answers1

1

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.

centic
  • 15,565
  • 9
  • 68
  • 125