How to send multiple emails in one session?

I want to send thousands of different emails to different recipients and would like to open the connection to my SMTP and hold it. I hope this is faster then reopen the connection for ervy mail. I would like to use Apache Commons Email for that, but could fall back to the Java Mail API if necessary.

Right now I'am doing this, what opens a closes the connection every time:

HtmlEmail email = new HtmlEmail();
email.setHostName(server.getHostName());
email.setSmtpPort(server.getPort());
email.setAuthenticator(new DefaultAuthenticator(server.getUsername(), server.getPassword()));
email.setTLS(true);
email.setFrom("test@example.com");
email.addTo(to);
email.setSubject(subject);
email.setHtmlMsg(htmlMsg);
email.send();
8
задан skaffman 18 May 2012 в 13:11
поделиться