背景

最近在全职负责的报表开发平台,有一个看板订阅功能,即按照设置的调度时间定时把看板数据加载为字节流发送到用户配置的指定邮箱。

然后偶发性地出现邮件发送失败问题,执行日志截图:

Sending the email to the following server failed.IOException while sending message问题解决_ssl

排查

上面报错日志:

ERROR MailService - sendEmail error
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.partner.outlook.cn:587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
at org.apache.commons.mail.Email.send(Email.java:1448)
at org.aaa.services.MailService.sendEmail(MailService.java:667)
at org.aaa.services.MailService.sendEmail(MailService.java:316)
at org.aaa.services.MailService.sendDashboard(MailService.java:138)
at org.aaa.services.job.JobService.sendMail(JobService.java:369)
at org.aaa.services.job.MailJobExecutor.execute(MailJobExecutor.java:129)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: javax.mail.MessagingException: IOException while sending message
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1244)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
... 8 common frames omitted
Caused by: java.net.SocketException: Connection reset
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at sun.security.ssl.OutputRecord.writeBuffer(OutputRecord.java:431)
at sun.security.ssl.OutputRecord.write(OutputRecord.java:417)
at sun.security.ssl.SSLSocketImpl.writeRecordInternal(SSLSocketImpl.java:876)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:847)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:128)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
at com.sun.mail.util.CRLFOutputStream.write(CRLFOutputStream.java:84)
at com.sun.mail.smtp.SMTPOutputStream.write(SMTPOutputStream.java:87)
at com.sun.mail.util.CRLFOutputStream.write(CRLFOutputStream.java:75)
at com.sun.mail.util.BASE64EncoderStream.write(BASE64EncoderStream.java:140)
at javax.activation.DataHandler.writeTo(DataHandler.java:309)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1608)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:961)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:553)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1608)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1849)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1196)

收不到邮件

几种可能:

  1. 用户已离职,此账户在LDAP系统已处于失效状态
  2. Sending the email to the following server failed.IOException while sending message问题解决_https_02

  3. 邮件地址有误,比如本应发送给@google.com,用户填写收件地址时写错为@gooogle.com
  4. 收件人的邮箱已满
  5. Sending the email to the following server failed.IOException while sending message问题解决_java_03

  6. 邮件内容体过大
  7. Sending the email to the following server failed.IOException while sending message问题解决_apache_04

  8. 邮件server端有发送记录却收不到邮件
    有些时候,mail server端有发送成功的记录,但是收件人反馈收不到邮件
  9. Sending the email to the following server failed.IOException while sending message问题解决_https_05

  10. 得找IT运维排查下邮件发送记录,以下面的截图为准
  11. Sending the email to the following server failed.IOException while sending message问题解决_java_06

  12. 邮件转发规则设置有误
  13. Sending the email to the following server failed.IOException while sending message问题解决_java_07

  14. 在outlook里面发送邮件,写草稿箱,是可以正常显示收件人信息:
  15. Sending the email to the following server failed.IOException while sending message问题解决_邮件发送_08

  16. 咨询运维,看日志是发送成功的:
  17. Sending the email to the following server failed.IOException while sending message问题解决_java_09

  18. 进一步看发送日志:
  19. Sending the email to the following server failed.IOException while sending message问题解决_apache_10

  20. 用户在outlook邮箱客户端,设置过转发规则,转出到外部邮箱,所以邮件发送动作被邮件服务器拒绝。

值得一提的是,客户端设置自动转发规则,有3种:

Sending the email to the following server failed.IOException while sending message问题解决_邮件发送_11


前两种是自己收到邮件之后,自己作为邮件发送方,再转发;第三种是直接转发出去。英文版本:

Sending the email to the following server failed.IOException while sending message问题解决_ssl_12


参考​​Redirect vs. Forward Email​

In a standard forward, the person forwarding the message appears to be the sender. In a redirection, the message appears to come from the original sender.