解决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