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?