gpt4 book ai didi

java - 向现有 MimeMessage 添加附件

转载 作者:行者123 更新时间:2023-11-29 03:27:31 33 4
gpt4 key购买 nike

我正在阅读这样的 Mime 消息:

             InputStream is = new FileInputStream("c:\\Temp\\test.eml");
MimeMessage message = new MimeMessage(session,is);

现在我只需要在现有的 MimeMessage 中添加一个附件,而无需更改任何其他内容。

我该怎么做?

我试过:

        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);

但它似乎改变了原来的消息。

最佳答案

因此,在这种情况下,答案将是创建一个包含旧消息内容的新消息,如下所示:Multipart multipart = (Multipart)message.getContent();

然后将附件添加到新邮件中。

关于java - 向现有 MimeMessage 添加附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20264964/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com