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?
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.
disabling norton smart firewall solved problem