解決530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM 步驟


報錯如下

 

java代碼中添加如下方法 props.put("mail.smtp.starttls.enable", "true");  報錯變化為如下

javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

缺少證書鏈的認證 需要將證書導入打jdk中(更換IBMJDK也解決了問題*)

1.獲取證書 

openssl s_client -showcerts -starttls smtp -crlf -connect smtp.office365.com:587 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > public.crt

2.導入證書到jdk 密碼是 changeit  或changit

keytool -import -alias outlook -keystore $JAVA_HOME/jre/lib/security/cacerts -file public.crt
keytool -list -keystore $JAVA_HOME/lib/security/cacerts

即可

 

*IBMJDK會報錯

javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory

解決方法

在<IBM_JAVA_HOME>/jre/lib/security/java.security文件尾添加以下內容:

ssl.SocketFactory.provider=
ssl.ServerSocketFactory.provider=

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM