メールの送信に javaMail API を使用していますが、コードは正常に動作していますが、問題は、メールの送信中にメールの送信に時間がかかっていることです (遅延時間は約 15 ~ 20 秒です)。これが原因で、アプリケーションがダウンしています。メールを送信する際に時間をかけずにメールを送信したいのですが、アイデアをください
ここに私のコードがあります:
public class sendMail {
public static void main(String[] args) {
Properties props = new Properties();
props=System.getProperties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
String mail="XYZ@gmail.com";
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abc@gmail.com","********");
}
});
try {
String emails="xyz@gmail.com"+","+"xyz.kannoju@vxyz.com";
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("xyz.rajender@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(emails));
message.setSubject("Testing Subject");
message.setText("Dear Rejender," +
"\n\n Please find the like!");
//Transport.send(message);
Transport tr=session.getTransport("smtp");
//tr.sendMessage(message, message.getRecipients(message.));
tr.send(message);
tr.close();
//Transport
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}