Thanks for the wonderful question! I get to use a little used class to help you out. So here we go...
The problem you have here is that you can't simply use a TCPClient class to just hookup to port 995 and start communicating much like you would if you were communicating to gmail on something like port 110 (standard pop3).
SSL is a security protocol which sits on top of the connection and used for encryption and security. Protocols like HTTP sit on top of SSL. So you can think of it as a sandwich... stream on the bottom, SSL in the middle, pop on top (hey it rhymes!)
This solution I am about to propose requires you to at least have .NET 2.0 SP1 or above. If you are using 2005 express, make sure you are patched up with SP1 and you should be good to go. In this version of the framework they have a class called
SslStream which wraps around a stream and provides this SSL support.
So you use TCPClient to generate a stream, get the stream, throw it into the SslStream class and use that as your read/write stream. Here is an example...
CODE
// Create our client and a SslStream variable (notice it is no longer NetworkStream)
TcpClient mail = new TcpClient();
SslStream netStream;
// Connect to gmail using 995 port
mail.Connect("pop.gmail.com", 995);
// Get the stream and toss it into the constructor of SslStream
// Now netStream is a SSL secured stream
netStream = new SslStream(mail.GetStream());
// Last thing you need is to authenticate as a client (you are connecting to them so you are the client and they are the server).
// You have to pass in the name on their certificate, which so happens to be the same host they are using for connecting. "pop.gmail.com"
netStream.AuthenticateAsClient("pop.gmail.com");
Once you authenticate as a client and tell them the name on their certificate, gmail deems you worthy to speak to. Just to clean a few things up, get rid of that line about StreamReader. Just read and write from netStream as you would a usual network stream.
All communications to and from Google on that stream is passed through SslStream for encryption/decryption and you are communicating with them.
There you go. Enjoy!
"At DIC we be SSL handling code ninjas!"