天天看點

Sending the email to the following server failed.IOException while sending message問題解決

背景

最近在全職負責的報表開發平台,有一個看闆訂閱功能,即按照設定的排程時間定時把看闆資料加載為位元組流發送到使用者配置的指定郵箱。

然後偶發性地出現郵件發送失敗問題,執行日志截圖:

Sending the email to the following server failed.IOException while sending message問題解決

排查

上面報錯日志:

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問題解決
  3. 郵件位址有誤,比如本應發送給@google.com,使用者填寫收件位址時寫錯為@gooogle.com
  4. 收件人的郵箱已滿
  5. Sending the email to the following server failed.IOException while sending message問題解決
  6. 郵件内容體過大
  7. Sending the email to the following server failed.IOException while sending message問題解決
  8. 郵件server端有發送記錄卻收不到郵件

    有些時候,mail server端有發送成功的記錄,但是收件人回報收不到郵件

  9. Sending the email to the following server failed.IOException while sending message問題解決
  10. 得找IT運維排查下郵件發送記錄,以下面的截圖為準
  11. Sending the email to the following server failed.IOException while sending message問題解決
  12. 郵件轉發規則設定有誤
  13. Sending the email to the following server failed.IOException while sending message問題解決
  14. 在outlook裡面發送郵件,寫草稿箱,是可以正常顯示收件人資訊:
  15. Sending the email to the following server failed.IOException while sending message問題解決
  16. 咨詢運維,看日志是發送成功的:
  17. Sending the email to the following server failed.IOException while sending message問題解決
  18. 進一步看發送日志:
  19. Sending the email to the following server failed.IOException while sending message問題解決
  20. 使用者在outlook郵箱用戶端,設定過轉發規則,轉出到外部郵箱,是以郵件發送動作被郵件伺服器拒絕。

值得一提的是,用戶端設定自動轉發規則,有3種:

Sending the email to the following server failed.IOException while sending message問題解決

前兩種是自己收到郵件之後,自己作為郵件發送方,再轉發;第三種是直接轉發出去。英文版本:

Sending the email to the following server failed.IOException while sending message問題解決