Getting certificate exception in asp.net webforms while sending email by using sendgrid

33 Views Asked by At

Sending email with attachment by using sendgrid in asp.net webforms application. In local it is working fine. but after deploy it on production iis getting below exception.

System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

The code is

var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, toList, subject, plainTextContent, htmlContent, true);

var response = await client.SendEmailAsync(msg).ConfigureAwait(false);

How to solve this?

1

There are 1 best solutions below

1
Eric Herlitz On

Your .NET application probably runs the wrong SecurityProtocol.

Try adding

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 

To your code

Or possibly

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;