Hossam Oukli
Hossam Oukli

Reputation: 1296

Javamail how to connect to IMAPs mail server, without certificate Validation

I'm trying to connect my Java application to a IMAP server mail on 993, in a test environment.

I'm trying to ignore the certificate validation ,using a recommendation from previous answers to a similar question, as follows:

imapProps.put("mail.imaps.ssl.checkserveridentity", "false");
imapProps.put("mail.imaps.ssl.trust", "*");

but it doesn't seem to work, I'am still getting an exception.

Cannot process current mailbox => sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:727)

So my question is, is it actually possible to use IMAPS protocol to connect to a mail server,without having to check or validate the certificate ?

If it is, choosing to ignore the certificate validation wouldn't it be a 2 sides decision then? JavaApp and the mailServer ?

Upvotes: 0

Views: 959

Answers (1)

Bill Shannon
Bill Shannon

Reputation: 29961

You need to use the same protocol name in both the properties and in the getStore method call. So, since you're setting the imaps properties, you should be using Store s = session.getStore("imaps");

Upvotes: 2

Related Questions