JAVAMAIL + ERROR +连接由远程主机关闭

时间:2014-02-25 18:08:19

标签: javamail

我正在尝试发送大量电子邮件,成就平均发送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;
    }
}

我忘记了什么?

1 个答案:

答案 0 :(得分:0)

服务器可能不希望您发送大量电子邮件,因此限制您的速度。打开JavaMail Session debugging,协议跟踪中的服务器可能会有更多信息。