I want to send thousands of different emails to different recipients and would like to open a connection to my SMTP and keep it on. Hope this is faster than reconnecting for ervy mail. I would like to use Apache Commons Email for this, but may return to the Java Mail API if necessary.
Now I am doing this, which opens closing 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();
java email apache-commons-email
Tim Büthe
source share