In the .NET framework there is a class TcpClient to retrieve emails from an email server. The TcpClient class has 4 constructors to connect with the server which take at most two parameters. It works fine with those servers which does not use SSL. But gmail or many other email providers use SSL for IMAP.
I can connect with gmail server but can not authenticate with email_id and password.
My code for authenticate user is
public void AuthenticateUser(string username, string password)
{
_imapSw.WriteLine("$ LOGIN " + username + " " + password);
//_imapSw is a object of StreamWriter class
_imapSw.Flush();
Response();
}
But this code can not login.
So how can I use the TcpClient class to retrieve emails when I have to use SSL?
You have to use the SslStream along with the TcpClient then use the SslStream to read the data rather than the TcpClient.
Something along the lines of:
EDIT
The above code will simply connect via SSL to Gmail and output the contents of a test message. To log in to a gmail account and issue commands you will need to do something along the lines of:
Obviously, without all the duplication of code 🙂