Reputation: 35
I get this Exception when I try to connect to the store.
As I look through forums, the solution to this error is to add the certificate to the truststore file of the used JVM.
The problem is I am new to this and I am not sure that I understand how I should do this exactly: Where should I get the certificate and how should I add it?
N.B: I notice that when I run this using main method, it works fine! But when I set a Scheduler to call the method automatically, that's when I get the exception.
Thank you a lot for the help.
public void receiveMails() throws Exception
{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.ssl.enable", "false");
props.setProperty("mail.imaps.socketFactory.port", "993");
props.setProperty("mail.imaps.starttls.enable", "true");
props.setProperty("mail.imaps.ssl.trust", "mailHost");
try
{
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("mailHost", "[email protected]", "password");
//...
The Exception is:
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:479)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
Upvotes: 0
Views: 1527
Reputation: 775
Try disabling your antivirus while doing this operation. This might be the cause.
Upvotes: 2