请在复制之前阅读我的问题。 使用自签名证书时,我已经阅读了很多关于这个错误的问题和答案。但是,我的问题是在尝试连接到 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/