解決錯誤503:com.sun.mail.smtp.SMTPAddressFailedException: 503 the server need auth(15D98013BE0)
最近遇見了一奇葩的問題:排查14年其他人開發的系統(已經接近退休的專案,突然領導要看)無法傳送郵件的過程中發現在linux下無法傳送郵件,並且報如下錯誤:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:com.sun.mail.smtp.SMTPAddressFailedException: 503 the server need auth(15D98013BE0)
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at com.platomix.yixintong.util.SimpleMailSender.sendMail(SimpleMailSender.java:72)
at com.platomix.yixintong.service.impl.ProxyServiceImpl.sendMail(ProxyServiceImpl.java:845)
at com.platomix.yixintong.action.ProxyAction.mirrorinterface(ProxyAction.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:774)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:662)
該問題奇葩就奇葩在:window環境下部署完全一樣的程式碼,執行時沒有問題的;可以正常傳送郵箱。
但是,部署在生產環境linux下程式碼完全一樣,出操作系統外其他環境完全一致;就是無法傳送郵件並且報如上錯誤。
但是這個503的錯誤百度和谷歌都沒有找到相關的錯誤材料(可能是因為程式碼太老了,之前沒有人遇到這種奇葩問題)。
通過多方測試和排查,最後給大家說下排查過程的收穫(原來是mail.ar的問題):
1.之前14年的程式碼中為mail.jar;該jar包執行下,專案是可以正常在window環境下進行正常執行發郵件,但是無法再linux(CentOS)環境下執行報錯503。
2.將程式碼替換新的jar包,mail-1.4.7.jar;重啟專案執行後;在window環境和linux環境下都可以完美的執行,並且成功傳送郵件。
還是jar包的原因,以後程式碼還要使用最新的jar省的有不相容的問題出現,並且難找。