How do I connect to a POP3 server over SSL using a custom TrustManager?
I am writing a test for an email sender class and I need to check if a message arrived by downloading it from a target POP3 server. The server is an Exchange server and the connection is only possible via SSL. The test will run periodically on the CI server, so the correct certification process is not possible. As far as I know, you can create your own TrustManager class that can accept any certificate. How can I tell my POP3 connection to use my own TrustManager? I don't see any way to do this in the current form of my code:
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
pop3Props.setProperty("mail.pop3.port", "995");
pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
URLName url = new URLName(provider, host, 995, "",
username, password);
Session session = Session.getInstance(pop3Props, null);
Store store = new POP3SSLStore(session, url);
store.connect();
source to share
Do you really need a trust manager?
You can also import your certificate into cacerts jdk files, then by default TrustManager will accept your ssl connection to your site.
Here you have a link to how you should import the server certificate:
http://javarevisited.blogspot.com/2012/03/add-list-certficates-java-keystore.html
source to share