使用Java Mail发送邮件时出错

时间:2015-06-30 08:45:45

标签: javamail

使用Java Mail发送邮件时收到以下错误。 以下是错误。你能否告诉我错误的原因。

ERROR :: Sending failed;
  nested exception is:
    class javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
  nested exception is:
    class javax.mail.SendFailedException: 452 Too many recipients received this hour

以下是导致异常的方法。

public void sendTextReport(DataBean dataBean,TextBean textBean)抛出IOException,MessagingException {

    Session session = getAuthentication();


        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(this.props.getProperty("from")));
        message.addRecipients(Message.RecipientType.TO,InternetAddress.parse(this.props.getProperty("textTo")));
        message.addRecipients(Message.RecipientType.CC,InternetAddress.parse(this.props.getProperty("textCc")));

        message.setSubject(" Report for the submissions between "+ dates.getDate1() + " and " + dates.getDate2());

        StringBuilder mailBody = new StringBuilder();

        mailBody.append("<text>Hi All,<br><br>Below is the Report for the submissions </text><br><br><br>");
        mailBody.append("<table><tr><th>Description</th><th>Count</th></tr>");

        LinkedHashMap map=(LinkedHashMap) getTextMap(dataBean,textBean);
        Iterator it=map.entrySet().iterator();
        while(it.hasNext()){
            Entry<String, Integer> entry=(Entry) it.next();
            mailBody.append("<tr><td>"+entry.getKey()+"</th><td class='count'>"+entry.getValue()+"</td></tr>");
        } 


        BodyPart messageBodyPart1 = new MimeBodyPart();

        messageBodyPart1.setContent(mailBody.toString(), "text/html");

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart1);

        message.setContent(multipart);

        Transport.send(message);

}

public Session getAuthentication() {

    final String host = this.props.getProperty("from");
    final String password = this.props.getProperty("password");
    properties.setProperty("mail.smtp.host", this.props.getProperty("hostName"));
    Session session = Session.getInstance(properties,null);
    return session;

}

textTo:此字符串包含3个电子邮件地址 textCc:此字符串包含1个分发列表,其中包含8个电子邮件地址。

所有都是有效的电子邮件地址。我在SendFailedException中检查了getValidUnsentAddresses()。所有这些都是有效但未发送。

1 个答案:

答案 0 :(得分:1)

这称为灰色列表。当您发送太多电子邮件(或更常见的情况 - 一定数量的收件人不存在的电子邮件)时,目标邮件服务器不会将您列入黑名单,而是暂时阻止从您的邮件服务器访问(实际上是邮件服务器的IP地址)。通常此块设置为1小时,但显然可能因配置而异。

你可以做几件事:

1.联系相关域的管理员(例如postmaster@messaging.sprintpcs.com)并请求将您的IP地址列入白名单。 (他们可能会拒绝)。

2.检查/增加时间电子邮件可以保留在您的本地队列中(以便有更多机会重试并最终交付。

3.为您的服务器添加更多公共IP地址