请在重复之前,请先阅读我的问题。
使用自签名证书时,我已阅读有关此错误的许多问题和解答。但是,我的问题是,尝试连接到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:找不到证书路径的信任锚。嵌套的异常是:javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。
现在,当涉及到自签名证书时,我会发生这种情况,但是为什么在尝试连接到GMAIL时收到此消息?您能帮我使我的应用程序正常工作吗?
最佳答案
可能是防火墙,防病毒或代理程序拦截了您连接到邮件服务器的请求,并提供了其证书而不是Gmail证书。使用InstallCert程序查看要提供给您的证书。
另一种可能性是信任库为空,丢失或配置错误,这就是为什么它找不到信任锚的原因。
关于android - Android JavaMail应用程序-CertPathValidatorException:找不到证书路径的信任 anchor ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28687123/