zoukankan      html  css  js  c++  java
  • 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); } }
    );

  • 相关阅读:
    Leetcode:50. Pow(x, n)
    loj 2759「JOI 2014 Final」飞天鼠
    bzoj 3569 DZY Loves Chinese II
    CF407D Largest Submatrix 3
    bzoj 3837 pa2013 Filary
    bzoj 4722 由乃
    CF1105E Helping Hiasat
    loj 6043「雅礼集训 2017 Day7」蛐蛐国的修墙方案
    luogu P2605 [ZJOI2010]基站选址
    luogu P3226 [HNOI2012]集合选数
  • 原文地址:https://www.cnblogs.com/zjf6666/p/12616902.html
Copyright © 2011-2022 走看看