POP3 SSL connection with javamail doesn't work
I have some troubles with POP3 SSL certificate.
This is my code:
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put("mail.host", "pop.gmail.com");
props.put("mail.store.protocol", "pop3s");
props.put("mail.pop3s.port", "995");
props.put("mail.pop3.ssl.trust","pop.gmail.com"); // or "*"
Session session = Session.getInstance(props);
session.setDebug(true);
Store store = session.getStore();
store.connect("mymail@gmail.com","mypassword");
Folder inbox = store.getFolder("INBOX");
if (inbox == null) {
throw new RuntimeException("INBOX Not found");
}
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
System.out.println("Found "+messages.length+" messages");
inbox.close(false);
store.close();
}
And this is the error during store.connect:
PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target
I read that seems to be an invalid certificate, I also tried to add
"mail.pop3.ssl.trust" property but it did not solve.
What can it be?
Thanks
No comments:
Post a Comment