【问题标题】:SendGrid SMTP error {"Unable to read data from the transport connection: net_io_connectionclosed."}SendGrid SMTP 错误 {“无法从传输连接读取数据:net_io_connectionclosed。”}
【发布时间】:2016-03-17 21:38:01
【问题描述】:

这似乎是重复的,但事实并非如此。我尝试重新启动 IIS,将 SMTPClient 包含在 using 块等中。但我仍然收到错误消息。

try
{
   //I have replaced sender@gmail.com and receiver@gmail.com by a valid gmail addresses
    MailAddress sender = new MailAddress("sender@gmail.com");
    MailAddress receiver = new MailAddress("receiver@gmail.com");
    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);
     }

这是一个用VS 2015开发的MVC应用。

对此的任何意见都会有所帮助。

【问题讨论】:

    标签: smtp sendgrid smtpclient


    【解决方案1】:

    就我而言,我没有注意到我在 web.config 设置中输入了错误的用户名

    【讨论】:

      【解决方案2】:

      您可以在登录https://app.sendgrid.com后进入Setup -> Guide -> Integrate SMTP查看SendGrid的SMTP配置

      【讨论】:

        猜你喜欢
        • 2016-02-21
        • 2015-03-02
        • 2013-12-12
        • 2013-07-04
        • 1970-01-01
        • 2022-08-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多