I have old version .net based project.
version is 4.5.2
Now I am trying to integrate Sendgrid to send email, but getting error. Below I am sharing code which I have tried and also error, if anyone can help me.
public void Email_ALL()
{
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
var sendclient = new SendGridClient("api-key");
var from = new EmailAddress("[email protected]", "Test");
var subject = "Sending with Twilio SendGrid is Fun";
var to = new EmailAddress("[email protected]", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var result = Task.Run(() => sendclient.SendEmailAsync(msg)).GetAwaiter().GetResult();
}
catch (Exception ex)
{
throw ex;
}
}
Error I am facing is below as well as I have attached screenshot.
System.Net.Http.HttpRequestException: 'An error occurred while sending the request.'
SocketException: An existing connection was forcibly closed by the remote host
2