1

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 Answer 1

0

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; 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Eric, Already added it. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12; Still not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.