Skip to content
Advertisement

Email not sent in @Async annotated method

I am trying to implement a function for user to download a file. The general workflow is as follows:

  1. User click the download button at frontend
  2. The backend will receive the download information from request, get data from database, and then generate zip file
  3. The file will be uploaded into cloud storage (Google in this case).
  4. An email with a signed URL will be sent to user to download the zip file from cloud.

All steps 2, 3 and 4 will be executed in a method annotated with @Async. The problem is if I restart the backend server and send only one download request, everything is fine which means the email can be received. However, it does not work after sending more download requests. No more emails will be sent. No errors, no warnings, but all the data required are received correctly, just no email was sent out.

Anyone knows what is the problem of it?

My Email Sender:

JavaScript

The email configuration file:

JavaScript

The async method to handle all logic

JavaScript

My thread pool configuration

JavaScript

Advertisement

Answer

in sendEmailWithSignedUrlToDownloadFile create the MimeMessage using

MimeMessage mimeMessage = mailSender.createMimeMessage();

instead of having a single instance of MimeMessage as member of the super class

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