首页 > 编程语言 > 详细

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

时间:2020-04-02 09:26:13      阅读:592      评论:0      收藏:0      [点我收藏+]

报错代码

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!