带有字节数组的邮件附件 [英] Mail Attachments with byte array
本文介绍了带有字节数组的邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为lSession的javax.mail.Session和一个MimeMessage lMessage:
I got a javax.mail.Session named lSession, and a MimeMessage lMessage :
Session lSession = Session.getDefaultInstance(properties);
MimeMessage lMessage = new MimeMessage(lSession);
我有一个包含文件表示的字节数组列表:
I got a List of Byte Array who contains file's representations :
List <byte[]> pPiecesJointes
我尝试将这些文件附加到邮件中,但我无法修复它... 。
I try to attach these file to the message, but I can't fix it....
if(!pPiecesJointes.isEmpty()){
lMultipart = new MimeMultipart();
lMessageBodyPart = new MimeBodyPart();
// text message
lMessageBodyPart.setText(pMessage);
lMultipart.addBodyPart(lMessageBodyPart);
for(int i = 0; i < pPiecesJointes.size(); i++){
lMessageBodyPart = new MimeBodyPart();
/* ?????? How add attachment in lMessageBodyPart with a Byte Array ?
*/
lMultipart.addBodyPart(lMessageBodyPart);
}
lMessage.setContent(lMultipart);
}
Transport.send(lMessage);
请问,如果有人知道谁用文件数组附加文件?
Please, if somebody knows who attach the file with a byte array ?
推荐答案
试用此代码:
MimeBodyPart att = new MimeBodyPart();
ByteArrayDataSource bds = new ByteArrayDataSource(bytearray, "AttName");
att.setDataHandler(new DataHandler(bds));
att.setFileName(bds.getName());
这篇关于带有字节数组的邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文