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!
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
Your particular error seems to indicate that your current SSL certificate is expired.
java.security.cert.CertPathValidatorException: timestamp check failed
You either need to renew your SSL certificate or configure your mail server to point to the correct one.
精彩评论