我正在尝试发送大量电子邮件,成就平均发送20封电子邮件然后我收到此错误:
javax.mail.MessagingException:无法向SMTP主机发送命令;嵌套异常是:java.net.SocketException:由远程主机关闭的连接
CODE JAVA:
public void mandarEmail(String correos, String mensaje, String asunto) {
final String username = "docs-gf@usmp.pe";
final String password = "Docpass";
Message message;
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.port", "587");
props.put("mail.smtp.host", "pod51004.outlook.com");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
message = new MimeMessage(session);
message.setFrom(new InternetAddress("Hello my friend"));
message.setSubject("I love u very much");
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ivan@hotmail.com"));
message.setContent(mensaje, "text/html; charset=utf-8");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
} finally {
props = null;
message = null;
}
}
我忘记了什么?