gpt4 book ai didi

spring - JavaMailSender 异常写入 Multipart

转载 作者:行者123 更新时间:2023-12-03 23:28:48 39 4
gpt4 key购买 nike

当我使用 JavaMailSender 发送带有附件的电子邮件时,它总是失败并抛出以下异常:

org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.IOException: Exception writing Multipart
; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.IOException: Exception writing Multipart
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1365)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:462)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:359)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:354)

这是我的代码

MimeMessage message = mailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(userName);
helper.setTo(toAddress);
helper.setSubject(subject);
FileSystemResource file = new FileSystemResource(filePath);
helper.addAttachment(file.getFilename(), file);
} catch (Exception e) {
log.error("oops..., ", e);
}
mailSender.send(message);

最佳答案

em,我靠运气解决了这个问题。

只需使用您的附件设置一个空文本内容,就像这样,它就可以工作。

helper.addAttachment(MimeUtility.encodeText("")), new ByteArrayResource(IOUtils.toByteArray(inputStream)));
helper.setText("", true);

关于spring - JavaMailSender 异常写入 Multipart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54452663/

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