Sending 120 mails by Javamail using Gmail account, but got exception after 80/90 mails

与世无争的帅哥 提交于 2020-01-05 12:09:11

问题


Got the below exception while send mails in a loop of 120. First 80/85 mails are success but the remaining got exceptions.

javax.mail.MessagingException: Can't send command to SMTP host; nested exception is: java.net.SocketException: Connection closed by remote host at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1564) at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1551) at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1489) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)

Below is my code for sending mails. From, To, Subject, Body etc. are same for all 120 mails.

    try {
        Transport tr = session.getTransport("smtp");
        tr.connect(this.SMTPServer, this.UserName, this.Password);
        System.out.println("Successfully connected to the mail server.");
        tr.sendMessage(message, message.getAllRecipients());
    } catch (Exception ex) {
        ex.printStackTrace();
    }

来源:https://stackoverflow.com/questions/10135927/sending-120-mails-by-javamail-using-gmail-account-but-got-exception-after-80-90

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!