1
Это может показаться дублирующим, но это не так. Я попытался перезапустить IIS, включив SMTPClient в блок использования и т. Д. Но все же я получаю ошибку.Ошибка SendGrid SMTP {«Невозможно прочитать данные из транспортного соединения: net_io_connectionclosed.»}
try
{
//I have replaced [email protected] and [email protected] by a valid gmail addresses
MailAddress sender = new MailAddress("[email protected]");
MailAddress receiver = new MailAddress("[email protected]");
MailMessage mailMsg = new MailMessage(sender, receiver);
mailMsg.Subject = "subject";
string text = "text body";
string html = @"<p>html body</p>";
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));
using(SmtpClient smtpClient = new SmtpClient())
{
smtpClient.Host = "smtp.sendgrid.net";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
//UserName = Username of SendGrid account, Password = Password of SendGrid account
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("UserName", "password");
smtpClient.Credentials = credentials;
smtpClient.ServicePoint.MaxIdleTime = 1; /* without this the connection is idle too long and not terminated, times out at the server and gives sequencing errors */
smtpClient.Send(mailMsg);
}
}
catch (SmtpException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Это приложение MVC разработан в VS 2015.
Любой вход на это будет полезно.