[英]Adding attachment to existing MimeMessage
I am reading a Mime message like this: 我正在阅读像这样的Mime消息:
InputStream is = new FileInputStream("c:\\Temp\\test.eml");
MimeMessage message = new MimeMessage(session,is);
Now i need to simply add an attachment to the existing MimeMessage without changing anything else. 现在我需要简单地添加一个附件到现有的MimeMessage而不改变任何其他东西。
How can i do this? 我怎样才能做到这一点?
I tried: 我试过了:
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource("C:\\attachment.pdf");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("encrypted_body.pdf");
multipart.addBodyPart(messageBodyPart);
// Send the complete message parts
message.setContent(multipart);
But it seems to change the original message. 但它似乎改变了原来的信息。
So, the answer in this case will be to create a new Message with the content of the old message like this: Multipart multipart = (Multipart)message.getContent();
因此,在这种情况下的答案是创建一个带有旧消息内容的新消息,如下所示:
Multipart multipart = (Multipart)message.getContent();
And then add the attachment to the new message. 然后将附件添加到新邮件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.