system.security.authentication.authenticationexception: the remote certificate is invalid according to the validation procedure.

Problem statement – While sending email using SMTP client using C# code, the following error comes up

system.security.authentication.authenticationexception: the remote certificate is invalid according to the validation procedure.

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

Solution – Add the code before calling smtpClient.Send(mail)

//Add following namespaces
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

smtpClient.EnableSsl = true;

ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s