Android JavaMail 应用程序 - CertPathValidatorException : Trust anchor for certification path not found

标签 android ssl jakarta-mail imap

请在复制之前阅读我的问题。 使用自签名证书时,我已经阅读了很多关于这个错误的问题和答案。但是,我的问题是在尝试连接到 GMAIL imap 服务器时出现此错误。所以,我真的需要一些帮助。我的代码是:

private String[] ReadMailbox(String MailboxName) throws IOException {
    Properties props = new Properties();
    props.setProperty("mail.store.protocol", "imaps");
    props.setProperty("mail.imaps.port", "993");
    List<String> FromAddressArrList = new ArrayList<String>();

    props.setProperty("mail.store.protocol", "imaps");
    try {
        Session session = Session.getInstance(props, null);
        Store store = session.getStore();
        store.connect("imap.gmail.com", "username", "password");
        ActiveMailbox = store.getFolder(MailboxName);
        ActiveMailbox.open(Folder.READ_ONLY);
        Message[] messages = ActiveMailbox.getMessages();
        for (int i = 0; i < messages.length; i++) {
            Message message = messages[i];
            Address[] from = message.getFrom();
            FromAddressArrList.add(from[0].toString());
        }
        //ActiveMailbox.close(true);
        store.close();
    } catch (NoSuchProviderException e) {
        FromAddressArrList.add(e.toString());
    } catch (MessagingException e) {
        FromAddressArrList.add(e.toString());
    }
    String[] FromAddressArr = new String[FromAddressArrList.size()];
    FromAddressArrList.toArray(FromAddressArr);
    return FromAddressArr;
}

我收到此错误消息:

javax.mail.MessagingException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.; nested exception is: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

现在,当涉及自签名证书时,我现在可能会发生这种情况,但为什么在尝试连接到 GMAIL 时会收到此消息?你能帮助我完成我的应用程序吗?

最佳答案

可能有防火墙或防病毒程序或代理程序拦截您连接到邮件服务器的请求并提供其证书而不是 Gmail 证书。使用 InstallCert程序以查看它向您出示的证书。

另一种可能是信任库为空或丢失或配置不正确,这就是它找不到信任 anchor 的原因。

关于Android JavaMail 应用程序 - CertPathValidatorException : Trust anchor for certification path not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28687123/

相关文章:

android - android pie 9.0 中的选项菜单文本颜色不同

java - 我的 DiffUtil 实现有什么问题?

带有 SSL 的 Java JMX 客户端

php - Ratchet 和 WSS 无法正常工作

android - 使用 FutureTask 调用 RESTful Web 服务

android - 从 Dagger 2 获取空实例

c# - 带有 SSL 的 webHttpBinding 的 WCF 配置在负载均衡器处终止

java - 如何从电子邮件中获取内联图像?

java - 来自数据库的 Spring Javamail 属性

java - Transport.send(msg) 不起作用