Search code examples
javaemailsslemail-client

Equivalent of openssl in Java


I am currently programming a pop3 email client to learn more about email clients and the RFC... The command: openssl s_client -connect pop.gmail.com:995 would connect to google server and will enable you to retrieve and check email after authentication. How would I do this in Java after initiating a TCP socket connection? A really bad alternative is to spawn a process that runs that command externally

Thanks


Solution

  • You would open a SSL Socket instead of a regular socket. SSLSockets require you to do a couple of extra things like setup the private key and a cert. If you search for "SSLSocket java examples" you should get a bunch of sample code to help you set it up. After you've created a SSLSocket and connected to gmail, you can get Input/Output streams from the socket just like you would with a regular Socket.

    Also see: Java client certificates over HTTPS/SSL