[Mono-list] SSL and SMTP

Abe Gillespie abe.gillespie at gmail.com
Tue Nov 11 11:29:47 EST 2008

I've successfully used the ICertificatePolicy hack before to connect
to https but this doesn't seem to work for sending Gmail.  Please see
the following code:

using System;
using System.Net;
using System.Net.Mail;

namespace Tester
    class Program
        static void Main(string[] args)
            var from = new MailAddress("from at gmail.com");
            var to = new MailAddress("to at gmail.com", "Sr. To");
            var mail = new MailMessage(from, to);

            // Set the content.
            mail.Subject = "Subject";
            mail.Body = "Test";

            // Send the message.
            SmtpClient smtp = new SmtpClient("smtp.gmail.com");
            smtp.EnableSsl = true;
            smtp.Credentials = new NetworkCredential("from at gmail.com",

            // No worky???
            ServicePointManager.CertificatePolicy = new


    public class TrustAllCertificatePolicy : ICertificatePolicy
        public TrustAllCertificatePolicy() { }

        public bool CheckValidationResult(
            ServicePoint sp, X509Certificate cert, WebRequest req, int problem)
            return true;

I'm getting the typical certificate exception:

System.IO.IOException: The authentication or decryption has failed.
---> System.InvalidOperationException: SSL authentication error:
  at System.Net.Mail.SmtpClient.<SmtpClient>c__38 (System.Object
sender, System.Security.Cryptography.X509Certificates.X509Certificate
certificate, System.Security.Cryptography.X509Certificates.X509Chain
chain, SslPolicyErrors sslPolicyErrors) [0x00000]

Is there any way to do this w/o the need of importing the certificate chain?


More information about the Mono-list mailing list