milosh milosh - 3 years ago 107
Android Question

Android JavaMail application - CertPathValidatorException: Trust anchor for certification path not found

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("", "imaps");
props.setProperty("mail.imaps.port", "993");
List<String> FromAddressArrList = new ArrayList<String>();

props.setProperty("", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("", "username", "password");
ActiveMailbox = store.getFolder(MailboxName);;
Message[] messages = ActiveMailbox.getMessages();
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
Address[] from = message.getFrom();
} catch (NoSuchProviderException e) {
} catch (MessagingException e) {
String[] FromAddressArr = new String[FromAddressArrList.size()];
return FromAddressArr;

And I get this error message:

javax.mail.MessagingException: Trust anchor for certification path not found.; nested exception is: 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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download