[Mono-list] Updating my gmail source code

Paul Johnson paul at all-the-johnsons.co.uk
Sat Feb 16 11:27:24 UTC 2013


I have on my website a nice simple way to connect to gmail and pull down 
emails with it. It worked. However, I've had an email from someone who 
decided to implement it to say it no longer worked. URL is 

Having looked over the code, it's down to the a TLSSecurity exception 
when trying to authenticate on the server. I've adjusted the code as 
follows, but I'm still getting the same error.

Code that failed

SslStream nstream;
public SslStream Connect(string username, string password)
    string message;
    string response;
    TcpClient tcpClient = new TcpClient();
    tcpClient.Connect("pop.gmail.com", 995);
    nstream = new SslStream(tcpClient.GetStream());
    nstream.AuthenticateAsClient("pop.gmail.com"); // fails
    response = Response(nstream);

adjusted code

public static bool Validator (object sender, X509Certificate 
certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
return true;

public SslStream Connect ()
string message = "", response = "";
ServicePointManager.ServerCertificateValidationCallback = Validator;
TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("pop.gmail.com", 995);
SslStream nstream = new SslStream (tcpClient.GetStream ());
nstream.AuthenticateAsClient ("pop.gmail.com"); // fail still

Any ideas on what I'm doing wrong?

The exact error is
System.IO.IOException: The authentication or decryption has failed --> 
Mono.Security.Protocol.Tls.TlsException: Invalid certificate received 
from the server


"Space," it says, "is big. Really big. You just won't believe how 
vastly, hugely, mindbogglingly big it is. I mean, you may think it's a 
long way down the road to the chemist's, but that's just peanuts to 
space, listen..."
Hitch Hikers Guide to the Galaxy, a truly remarkable book!

More information about the Mono-list mailing list