gpt4 book ai didi

java - 从 bytearrayoutputstream 添加附件到邮件

转载 作者:行者123 更新时间:2023-11-29 08:40:06 32 4
gpt4 key购买 nike

我正在尝试发送带有附件的电子邮件:

MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, CharEncoding.UTF_8);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
message.addAttachment("facture.pdf", new ByteArrayResource(IOUtils.toByteArray(is)));

我收到一个错误:

java.lang.IllegalStateException: Not in multipart mode - create an appropriate MimeMessageHelper via a constructor that takes a 'multipart' flag if you need to set alternative texts or add inline elements or attachments.

有没有办法让它在保留 addAttachment 方法的情况下工作?

最佳答案

MimeMessageHelper的文档看来,您只需传递一个 true 标志。

MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, CharEncoding.UTF_8);

关于java - 从 bytearrayoutputstream 添加附件到邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40914984/

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