码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-04-02 01:43:13      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:fail   enable   有道翻译   tin   socket   soc   instance   hbuilder   邮件   

报错代码

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); } }
);

 

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

标签:fail   enable   有道翻译   tin   socket   soc   instance   hbuilder   邮件   

原文地址:https://www.cnblogs.com/zjf6666/p/12616902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!