java – Apache Commons Email with attach with base64
作者:互联网
我正在尝试通过apache.commons.mail发送一个base64编码的文件,我只是无法找到它应该去的Content-Transfer-Encoding:base64标头.
// Create the email
MultiPartEmail email = new MultiPartEmail();
email.setSmtpPort(587);
email.setDebug(false);
email.setHostName("smtp.gmail.com");
email.setAuthentication("from@gmail.com", "password");
email.setTLS(true);
email.addTo("to@example.com");
email.setFrom("from@example.com");
email.setSubject("subject");
email.attach(new ByteArrayDataSource(
Base64.encodeBase64(attachFull.getBytes()), "text/plain"),
"samplefile.txt",
"sample file desc",
EmailAttachment.ATTACHMENT
);
而这正是收件人所获得的.
------=_Part_0_614021571.1334210788719
Content-Type: text/plain; charset=Cp1252; name=texto.txt
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=samplefile.txt
Content-Description: sample file desc
我如何指定该文件是Base64编码?
解决方法:
您可以尝试覆盖attach
方法并在其中设置Content-Transfer-Encoding标头.默认情况下,框架不会为您设置它或干净地公开MIME bodyPart.
标签:java,base64,apache-commons-email 来源: https://codeday.me/bug/20190530/1183758.html