Javamail, Transport.send () is very slow

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; } } 
+4
source share
1 answer

Ok, thanks for your suggestions.

My decision:

 Transport transport = session.getTransport("smtp"); transport.connect(this._properties.getProperty("mail.smtp.host"), Integer.parseInt(this._properties.getProperty("mail.smtp.port")), this._properties.getProperty("mail.smtp.user"), this._properties.getProperty("mail.smtp.password")); Address[] addr = new Address[this._addresses.size()]; for (int i = 0, c = this._addresses.size(); i < c; i++) { addr[i] = new InternetAddress(this._addresses.get(i)); } transport.sendMessage(message, addr); 
+6
source

Source: https://habr.com/ru/post/1435310/


All Articles