参照EmailServiceImpl里的实现,往自己的一个163邮箱发送500封邮件,结果好几次都是到了大概250封左右,后台抛异常
Caused by: 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:2306)
at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2293)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1333)
at javax.mail.Transport.send0(Transport.java:257)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
... 8 more
是不是163邮箱的防垃圾邮件的设置啊,连续接收到邮件,认为是垃圾邮件,关闭连接了?
还是本身代码的问题
@Inject("refer:$ioc")
protected Ioc ioc;
public boolean send(String to, String subject, String html) {
try {
HtmlEmail email = ioc.get(HtmlEmail.class);
email.setSubject(subject);
email.setHtmlMsg(html);
email.setCharset("utf-8");
email.addTo(to);
email.buildMimeMessage();
email.sendMimeMessage();
return true;
} catch (Throwable e) {
log.error("send email fail", e);
return false;
}
}