我正在使用 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);
}
}