我有一个方法,发送许多电子邮件到交换服务器通过smtp使用JavaMail,下面是我的代码,
public void sendMail(){
final String host="host",port="587",username="mail1@local.local",password="password",from="";
try {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
props.put("mail.smtp.ssl.trust", host);
final String email = from;
Authenticator authenticator = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getInstance(props,authenticator);
InternetAddress replyToAddress [] = new InternetAddress[1];
replyToAddress[0] = new InternetAddress("mail1@local.local");
Transport transport = session.getTransport("smtp");
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("mail1@local.local"));
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("mail2@local.local"));
mimeMessage.setSubject("Test");
mimeMessage.setText("Hello Testing");
mimeMessage.setReplyTo(replyToAddress);
transport.send(mimeMessage);
System.out.println("Email has been Sent Successfully to");
} catch (MessagingException e) {
e.printStackTrace();
}现在,当我应用一个循环并调用这个函数10次时,只有前5封电子邮件被成功发送,对于其余的请求,我得到了以下异常,
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:2157)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2144)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1210)
at javax.mail.Transport.send0(Transport.java:197)
at javax.mail.Transport.send(Transport.java:124)如果我增加请求计数,那么仍然只发送前五封电子邮件,其余的抛出异常。
如果我将失败的请求放在某个队列中,稍后重试,则会发送其中的一些请求。
如果有任何提示,我是否需要检查Exchange服务器上的某些配置?
发布于 2017-07-12 00:02:29
我们已经在MS Exchange Server 2010中看到了完全相同的问题。我们必须通过发出以下Powershell-命令来提高ReceiveConnector消息速率限制:
Set-ReceiveConnector "Client CLIENTNAME" -MessageRateLimit unlimitedhttps://stackoverflow.com/questions/36058513
复制相似问题