邮件连续多次发送失败
在发送邮件的时候时间间隔长一点没有问题,如果是连续多次发送就不行了
有如下异常:
Sending failed;
nested exception is:
class javax.mail.MessagingException: 554 Remote Return: 450 <DATA>: Data command rejected: Try again 2 minutes later
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
程序是这样:
public boolean send(){
try {
Properties props = new Properties();
Session sendMailSession;
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host", smtpServer); //smtp主机名
props.put("mail.smtp.user",address); //发送方邮件地址
props.put("mail.smtp.password",password); //邮件密码
PopupAuthenticator popA=new PopupAuthenticator();//邮件安全认证
popA.performCheck(username,password); //填写用户名及密码
sendMailSession = Session.getInstance(props, popA);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(address));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(takeAddress)); //接收方邮件地址
newMessage.setSubject(title);
newMessage.setSentDate(new Date());
newMessage.setText(text); //邮件正文
Transport.send(newMessage);
return true;
}
catch (MessagingException ex)
{
ex.printStackTrace();
return false;
}
}