javax.mail.MessagingException: Could not convert socket to TLS


报错代码

javax.mail.MessagingException: Could not convert socket to TLS;   

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

首先有道翻译后看着好像是证书问题。然后百度了下。看到很多人遇到这些问题,就一个个试一下

 

原先获取 smtp 的写法

Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");

Session session = Session.getDefaultInstance(props);

 

后来试下加上了 代码(host是邮箱服务器地址),可以发送了。网上说的大概意思就是设置服务是可以信任的,不需要安全证书

props.put("mail.smtp.ssl.trust", host);

如果还不可以可能就是调用ssl加密 ,网上搜下怎么发送ssl加密的发送邮件方法

或者试试创建session的其他方法

Session session = Session.getInstance(props, new javax.mail.Authenticator()
{ protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(username, password); } }
);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM