Karatas, FERHAT
I would love to change the world, but they won't give me the source code!
The remote certificate is invalid
24.06.2009 22:54:49 - Filed under : C# | Asp.net
If I enable EnableSsl for smtpclient am getting an exception: "The remote certificate is invalid according to the validation procedure."

It means the server certificate isn't valid by regular validation rules. You can simply use this snippet to by-pass it:
public static bool AcceptAllCertificatePolicy(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; }

public static void SendMail(string body, string to, string subject, string attachFilename)
{
  MailMessage message = new MailMessage();
  message.Priority = MailPriority.Normal;
  message.To.Add(new MailAddress(to));
  message.Subject = subject;
  message.IsBodyHtml = true;
  message.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-9");
  message.Body = body;

  if (attachFilename != string.Empty)
  {
    message.Attachments.Add(new Attachment(attachFilename));
  }

  ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertificatePolicy;
  SmtpClient client = new SmtpClient();
  client.EnableSsl = true;
  client.Send(message);
}

Keywords : Smtpclient, asp.net, system.net.mail, EnableSSL, validation.
with 0 comments

What do you think ?
Security Code 760
Check S. Code
Name  
Email  
Home Page  
Comments