Android JavaMail application - CertPathValidatorException: Trust anchor for certification path not found

我与影子孤独终老i 提交于 2019-12-19 11:59:31

问题


Please, before making this a duplicate, read my problem. I have read many questions and answers about this error when using self signed certificates. But, my problem is that I get this error when trying to connect to GMAIL imap server. So, I really need some help. My code is:

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

And I get this error message:

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.

Now, I now this can happen when there are self signed certificates involved, but why do I get this message when trying to connect to GMAIL? Can you help me to make my application work?


回答1:


There might be a firewall or anti-virus or proxy program that's intercepting your request to connect to your mail server and providing its certificate instead of the Gmail certificate. Use the InstallCert program to see what certificate it's presenting to you.

Another possibility is that the trust store is empty or missing or incorrectly configured, which is why it can't find the trust anchor.




回答2:


disabling norton smart firewall solved problem



来源:https://stackoverflow.com/questions/26470491/android-javamail-application-certpathvalidatorexception-trust-anchor-for-cert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!