Search code examples
sslimapjakarta-mail

javamail connect to imap over ssl to read mails


I want to read emails from exchange server over IMAP SSL with JavaMail API. I am using the following piece of code.

Properties props =System.getProperties();

props.setProperty("mail.store.protocol","imaps");

Session session = Session.getDefaultInstance(props, null);

Store store = session.getStore("imaps");

store.connect("server hostname","username","password");

But I am unable to establish a connection. All I get is following error.

javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed; nested exception is: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:618) at javax.mail.Service.connect(Service.java:291) at javax.mail.Service.connect(Service.java:172) at

I am not sure if there are any pre-requisite steps to be followed for establishing a connection.

Appreciate your help!


Solution

  • to which mail server u r trying to connect?? replace IMAPS with IMAP and try it.

    If you really need to use IMAPS try this

    http://blogs.oracle.com/andreas/entry/no_more_unable_to_find