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("[EMAIL PROTECTED]");
            var to = new MailAddress("[EMAIL PROTECTED]", "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("[EMAIL PROTECTED]",
"p4ssw0rd");

            // No worky???
            ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();

            smtp.Send(mail);
        }
    }

    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:
RemoteCertificateChainErrors
  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?

Thanks.
-Abe
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to