Reputation: 2115
Recently, I have been into writing a proxy server in Java. The server, I have written, can handle GET and POST methods. However, it doesnt support HTTPS protocol. Googling didn
t help a lot. I just came to know that I will have to implement the CONNECT method too(and we got to use HTTP TUNNELING). But, how am I going to get this thing work, I don`t have the vaguest idea. It would be helpful if you let me some useful links or help me out with a rough idea..
I tried using the following code but got stuck after a while:
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
Socket tunnel = new Socket ("127.0.0.1",8036);
OutputStream serverOut = tunnel.getOutputStream();
String requestSSLServer = "CONNECT " + urlServer + " HTTP/1.0 \n" + secondLine + "\r\n";
byte b[];
b= requestSSLServer.getBytes("ASCII7");
serverOut.write(b);
What should be the IP-address and port number passed to Socket object?? What should I do next?? What should I do next??
Upvotes: 1
Views: 1339
Reputation: 8374
What you've written is an HTTP proxy. Email uses protocols that have nothing to do with HTTP. Learn about those protocols (POP, SMTP and IMAP) and then come back to this task.
Upvotes: 1
Reputation: 6124
Writing a mail relay is more complicated than a http proxy as headers are different and you will have to change/set some of those on the fly. However, if you are looking to provide a mail (send) relay, then the standard port for SMTP (sending mail) is 25; however, since this is plain text, if authentication is involved you will have to probably have to use smtps (secure SMTP) which is 465. If you are looking to provide an imap (read mail) proxy then the port is 143 or 220 (for imap3) -- also for imaps (secure imap) is 993. Last but not least, if you're looking to provide a POP (read mail) proxy then the port for pop2 is 109 and 103 for POP3 (which is widely spread nowadays -- I don't know of anyone still using POP2). Also secure POP3 is on port 995.
Upvotes: 1