I wrote a method for sending emails in bulk, but it is very slow (about 3 emails every 10 seconds). I want to send thousands of letters. Is there any way to do this much faster?
I use gmail now, but only for the test, and finally want to send using my own SMTP server.
Here is the code:
public boolean sendMessages() { try { Session session = Session.getInstance(this._properties, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("user", "password"); } }); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(this.getFrom())); message.setSubject(this.getSubject()); message.setText(this.getBody()); for (int i = 0, c = this._addresses.size(); i < c; i++) { message.setRecipient(Message.RecipientType.TO, new InternetAddress(this._addresses.get(i))); Transport.send(message); } return true; } catch(AuthenticationFailedException e) { e.printStackTrace(); return false; } catch(MessagingException e) { e.printStackTrace(); return false; } }
mitch source share