You could try to handle the certificate validation event to make it easier to determine the reason why the remote certificate is considered invalid. For this, before calling the SendEmail method add the following line:
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
and then provide an implementation for ValidateServerCertificate, like
public bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
// replace with proper validation
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
else
return false;
}
The parameters received by ValidateServerCertificate should give you details about why the validation fails (check sslPolicyErrors). You also have access to the remote certificate and chain of certificate authorities.
One possible scenario is that you run the website under a different user than the console application, and this user does not trust the issuer (or a intermediary authority in the chain) of the gmail's certificate. This might happen if you somehow have deleted certificates from the Local Machine/Trusted Root Certificates in Windows Certificate Store.