How to connect/telnet to SPOP3 server using java (Sockets)?

家住魔仙堡 提交于 2019-12-24 08:35:53

问题


In case of POP3 it is possible to connect via telnet using sockets over port 110, But how to do it , if SPOP3 is implemented. With normal telnet it can be done quite easily with

Socket pop3Socket = new Socket(host.com, 110);

FYI: For connecting to SPOP3 we use in linux/unix

 openssl s_client -connect servername.com:995

回答1:


You'll need to use the SSLSocket class. An example can be found at: http://www.herongyang.com/JDK/SSL-Socket-Client-Example-SslSocketClient.html.

Basically, you'll do something like:

SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket c =        (SSLSocket) f.createSocket("localhost", 8888);

If the endpoint has a self signed certificate then you have two options:

  1. Add this self-signed cert to your local keystore. This URL gives a good overview: http://www.chrissearle.org/blog/technical/adding_self_signed_https_certificates_java_keystore
  2. Create a TrustManager that does not validate the server's certificate: http://www.howardism.org/Technical/Java/SelfSignedCerts.html

Option 1 is more secure.



来源:https://stackoverflow.com/questions/14811844/how-to-connect-telnet-to-spop3-server-using-java-sockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!