Spring Boot Mail not sending attachments

I am building a Mail notifiaction system, that should attach PDF reports that are stored in an S3 bucket. I followed the documentation, but the attachment is not displayed by Outlook. Here is my code for actually sending the mail:
@Observed(name = "mail.send", contextualName = "sending-templated-mail")
public void sendMailFromTemplate(MailInstance instance){
// Loading a template
try {
// Conditioning metadata
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setTo(instance.dest());
helper.setFrom(instance.src());
helper.setSubject(subject);
helper.addInline("logo", logoFile);
message.setContent(result, "text/html");
List<File> toClean = new ArrayList<>();
instance.attachments().forEach(item -> {
log.info(item);
try {
InputStream stream = fileService.download("test-results", item);
File f = new File(scratch, item);
FileUtils.copyToFile(stream, f);
FileSystemResource resource = new FileSystemResource(f);
helper.addAttachment(item.split("/")[1], resource);
toClean.add(f);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
});
sender.send(message);
log.info("Cleaning cache directory");
toClean.forEach(File::delete);
} catch (MessagingException | TemplateException | IOException e) {
throw new RuntimeException(e);
}
}
@Observed(name = "mail.send", contextualName = "sending-templated-mail")
public void sendMailFromTemplate(MailInstance instance){
// Loading a template
try {
// Conditioning metadata
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
helper.setTo(instance.dest());
helper.setFrom(instance.src());
helper.setSubject(subject);
helper.addInline("logo", logoFile);
message.setContent(result, "text/html");
List<File> toClean = new ArrayList<>();
instance.attachments().forEach(item -> {
log.info(item);
try {
InputStream stream = fileService.download("test-results", item);
File f = new File(scratch, item);
FileUtils.copyToFile(stream, f);
FileSystemResource resource = new FileSystemResource(f);
helper.addAttachment(item.split("/")[1], resource);
toClean.add(f);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
});
sender.send(message);
log.info("Cleaning cache directory");
toClean.forEach(File::delete);
} catch (MessagingException | TemplateException | IOException e) {
throw new RuntimeException(e);
}
}
I don't know if this is a thing with outlook, or with my code.
1 Reply
JavaBot
JavaBot•9mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server