Reputation: 1229
I know there are a lot of question regarding the same thing on SO, but I don't seem to have found the solution for my problem yet.
I am using JavaMail API to connect to a mail server. Initially I used the port 110 to connect to pop3 server and that is when I got the following exception -
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
I changed the port to 995 and got the following exception -
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Code for connecting to the server:
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "pop3");
props.setProperty("mail.pop3.ssl.enable", "true");
Session session = Session.getInstance(props, null);
store = session.getStore("pop3");
store.connect(ServerName, Port, UserName, Password);
Where am I going wrong? Any advice would be helpful. Thanks in advance.
Upvotes: 0
Views: 684
Reputation: 310909
The first error message says it all. You're attempting SSL to a plaintext port. Try disabling SSL, or use the correct port for SSL.
The second one says that your truststore doesn't trust the server certificate. If it's self-signed, you will need to import it into your truststore.
Upvotes: 2