Edmond Edmond - 1 year ago 88
Java Question

Quartz job to send email using Javamail, but Javamail is synchronous

The title basically sums up my issue at the moment. If I have multiple instances of the Job running at/around the same time, Javamail throws an exception as it's meant to be used synchronously. Is there a way I can make it run asynchronously? Or is there an alternative to Javamail that is asynchronous?

Answer Source

I think there are several ways to deal with such kind of tasks:

  1. wrap up into a service which then periodically send batch of emails;
  2. send each email in its on thread, i.e. imply separate SMTP connection;

    public void sendEmail(String smtpServer, String to,String from,String subject, String body) {
          send(smtpServer, to, from, subject, body);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download