'Springboot: sending an email with attachment
I have this piece of code to send emails in SpringBoot, that is working fine, but I have this error:
Failed messages: javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.net.ssl.SSLException: java.net.SocketException: Broken pipe (Write failed)
when I send big files, like 88MB
public void sendMailWithAttachment(String to, String subject, String body, String fileToAttach) {
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.setTo(to);
message.setFrom(new InternetAddress("[email protected]"));
message.setSubject(subject);
message.setText(body);
FileSystemResource file = new FileSystemResource(new File(fileToAttach));
message.addAttachment("logo.jpg", file);
};
try {
javaMailSender.send(preparator);
}
catch (Exception ex) {
// simply log it and go on...
System.err.println(ex.getMessage());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
