[Mono-dev] sending smtp email under SSL

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Tue Jul 14 18:09:52 EDT 2009


Try setting the certificate validation callback.

If you're running mono from HEAD (if you don't know what this is, you
are not):

---------------
        // This will trust *any* certificate
        ServicePointManager.ServerCertificateValidationCallback +=
        delegate(object sender, X509Certificate certificate, X509Chain
        chain, SslPolicyErrors sslPolicyErrors)
        {
        	return true;
        }
-------------

If you're running mono 2.4.2.1 or earlier check out
http://www.mono-project.com/UsingTrustedRootsRespectfully and here's the
sample:
------------------------
public class NoCheckCertificatePolicy : ICertificatePolicy {
    public bool CheckValidationResult (ServicePoint a, X509Certificate
b, WebRequest c, int d)
    {
      return true;
    }
}
...
ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
----------------------


-Gonzalo


On Thu, 2009-07-09 at 18:56 -0700, _KD_ wrote:
> 
> 
> gedw99 wrote:
> > 
> > Hey,
> >  
> > i am trying to send an email using a gmail account.
> > According to the docs, Network Credentials does not support SSL.
> > http://www.go-mono.com/docs/index.aspx?link=T%3ASystem.Net.NetworkCredential%2F*
> >  
> > I am using the latest mono 1.2, and XPS2 !
> > Is there an alternative way to send email under SSL ????
> >  
> > Code and error below::::
> >  
> >  
> > SmtpClient mailClient = new SmtpClient();
> > mailClient.EnableSsl = true;
> > mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
> > mailClient.Host = "smtp.gmail.com";
> > mailClient.Port = 587;
> > mailClient.Credentials = new NetworkCredential(Config.GMAIL_UserName,
> > Config.GMAIL_PassWord);
> > mailClient.Send(this._from, this._to, this._subject, this._body);
[...]





More information about the Mono-devel-list mailing list