Skip to content
Advertisement

Adding multipart file as an attachment to an email in Spring Boot

I want to send an email from Spring Boot with a pdf attachment. I have received the pdf file as a multipart file from a POST call.

Here’s my controller class so far (sendEmails method is included in emailService service):

JavaScript

And here’s sendEmails method:

JavaScript

Now, in the sendEmailAndUpdate method I have the reciever’s email address, the pdf (as a MultipartFile), and the JavaMailSender. Here’s this method so far:

JavaScript

Here I want to attach the pdf file (which I have as a MultipartFile) to the email. This might be a noob question and I might be missing something obvious, but I’m new to this and I couldn’t find any resources online on how to do this. Can anyone link me to such resource or provide with a solution? Thank you in advance.

Advertisement

Answer

You can attached directly

JavaScript

MultipartFile already extend class of InputStreamSource

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement