Apache的百科全书电子邮件连接code与附加的base64 [英] Apache Commons Email encode attach with base64
问题描述
我想通过 apache.commons.mail
来发送文件的base64恩codeD和我不能缝获得内容传输编码:BASE64
头在那里它应该去的。
I'm trying to send a file base64-encoded via apache.commons.mail
and I just can't seam to get the Content-Transfer-Encoding: base64
header where it's supposed to go.
// 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
);
而这正是到达收件人。
And this is what gets to the recipient.
------=_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 EN codeD?
推荐答案
您可以尝试重写<一个href=\"http://commons.apache.org/email/api-release/org/apache/commons/mail/MultiPartEmail.html#attach%28%29\"相对=nofollow> 连接
方法和设置内容传输编码
头在那里。默认情况下,框架不设置它为您或干净暴露身体部位MIME
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.
这篇关于Apache的百科全书电子邮件连接code与附加的base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!