версия — 4.5.2
Сейчас я пытаюсь интегрировать Sendgrid для отправки электронной почты, но получаю ошибку. Ниже я делюсь кодом, который я пробовал, а также ошибкой, если кто-нибудь может мне помочь.
Код: Выделить всё
public void Email_ALL()
{
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
var sendclient = new SendGridClient("api-key");
var from = new EmailAddress("hello@test.com", "Test");
var subject = "Sending with Twilio SendGrid is Fun";
var to = new EmailAddress("Test@gmail.com", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "[b]and easy to do anywhere, even with C#[/b]";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var result = Task.Run(() => sendclient.SendEmailAsync(msg)).GetAwaiter().GetResult();
}
catch (Exception ex)
{
throw ex;
}
}
Код: Выделить всё
System.Net.Http.HttpRequestException: 'An error occurred while sending the request.'
SocketException: An existing connection was forcibly closed by the remote host

Подробнее здесь: https://stackoverflow.com/questions/793 ... -net-4-5-2
Мобильная версия