Apache Commons Email encode attach with base64

独自空忆成欢 提交于 2019-12-01 19:38:29

You might try overriding the attach method and set the Content-Transfer-Encoding header in there. By default the framework doesn't set it for you or expose the MIME bodyPart cleanly.

The easiest solution would be to do something like this:

// create a multipart leg for a specific attach
MimeMultipart part = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler (new DataHandler(new ByteArrayDataSource(attachFull.getBytes(), "text/plain")));
messageBodyPart.removeHeader("Content-Transfer-Encoding");
messageBodyPart.addHeader("Content-Transfer-Encoding", "base64");
part.addBodyPart(messageBodyPart);
email.addPart(part);

And javax will automatically convert your file to base64.

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!