【发布时间】:2014-12-15 17:18:32
【问题描述】:
请在复制之前阅读我的问题。 在使用自签名证书时,我已经阅读了许多关于此错误的问题和答案。但是,我的问题是在尝试连接到 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 时会收到此消息?你能帮我完成我的应用程序吗?
【问题讨论】:
标签: android ssl jakarta-mail imap