【问题标题】:Office 365 SMTP starts firing net_io_connectionclosedOffice 365 SMTP 开始触发 net_io_connectionclosed
【发布时间】:2015-04-06 09:08:01
【问题描述】:

不久前,我已将我的 ASP.NET C# 项目配置为通过 Office 365 发送电子邮件,但上周它开始抛出很多异常。

System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. 
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) 
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) 
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) 
at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) 
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) 
at System.Net.Mail.SmtpClient.Send(MailMessage message)

如何防止这种情况发生?

  MailMessage message = new MailMessage(System.Configuration.ConfigurationManager.AppSettings["smtpfrom"], email, strOnderwerp, strBody);
            message.Priority = MailPriority.Normal;
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["smtpserver"], Convert.ToInt32((System.Configuration.ConfigurationManager.AppSettings["smtpport"])));

            client.EnableSsl = Boolean.Parse(System.Configuration.ConfigurationManager.AppSettings["smtpssl"]); ;
            client.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["smtpuser"], System.Configuration.ConfigurationManager.AppSettings["smtppass"]);

            client.Send(message);
            client.Dispose();

Dispose 上似乎抛出了异常。

【问题讨论】:

  • 与您的问题无关,但我会从您的电子邮件发送代码中收到ConfigurationManager 的电话。我会编写一个用于发送电子邮件的通用方法(例如名称:SendEmail),并将这些值作为变量传递。将调用ConfigurationManager 放在调用SendEmail 的任何方法中。嗯......实际上我会将我的 ConfigurationManager 调用包装在一个特定于返回 Config 值的规范化类中,所以我可以将它编码为变量 MyAppConfigClass.SmtpServer

标签: c# asp.net smtp office365


【解决方案1】:

我的公司于 2 月 8 日开始出现同样的问题。问题来来去去,没有规律可循。

我认为解决问题的方法是更改​​ SMTP 服务器地址。

我们原来的 SMTP 服务器地址是 podxxxxx.outlook.com,并且大部分时间仍然有效。我在我们的门户中检查了当前的 O365 SMTP 服务器地址,它应该是 smtp.office365.com。

我将配置更改为指向这个新地址,问题似乎已经消失。我的日志在更改后的过去 24 小时内没有显示任何错误。

如果错误再次发生,我会更新这个。

【讨论】:

  • 已将 pod51014.outlook.com 替换为 smtp.office365.com - 希望是最好的。
【解决方案2】:

在我们的例子中,我们已经在使用smtp.office365.com 端点,但突然之间,我们开始在我们的一台机器上收到net_io_connectionclosed,而相同的代码在其他机器上运行良好。调查表明,这些机器将 smtp.office365.com 解析为不同的 IP 地址,看起来其中一台服务器行为异常。

在尝试编写支持查询时,微软似乎在欺骗我们:

最近,我们开始拒绝一定比例的与 使用 TLS1.0/1.1 进行 SMTP AUTH 的 smtp.office365.com(完成 禁用将于 2022 年初开始)。

仅此而已。 Switching to TLS 1.2 修复了整个事情。

【讨论】:

  • 它被称为“减速带”,显然,微软确实 return a useful error message: 421 4.7.66 TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit https://aka.ms/smtp_auth_tls. 只是(旧的).NET SmtpClient 类丢弃了这些信息并显示(无用的)通用 net_io_connectionclosed 消息。
  • 是的,我必须将 SMTP 地址更新为 smtp-legacy.office365.com 并在 Exchange 管理中心 -> 设置 -> 邮件流中启用旧版 TLS 客户端“启用旧版 TLS 客户端的使用”。 Opt in to the Exchange Online endpoint for legacy TLS clients using SMTP AUTH
【解决方案3】:

在 VB.NET 或 c# 中连接到 Office365 时,所有这些因 net_io_connectionclosed 错误而烦恼的圣杯是 TSL 版本。

当您使用想要连接的 VB.NET oder c# 应用程序时,发送接收消息。往返 O365,您必须在代码中强制使用 TLS12。

只需将最后一行放在 EnableSSL = True 下方即可:

Last Line to force TLS12

【讨论】:

    【解决方案4】:

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |安全协议类型.Tls11 |安全协议类型.Tls12;

    这对我有用

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案5】:

    如果大家都在 2022 年遇到这个问题,那可能是微软决定停止对服务端点“smtp.office365.com”支持 TLS1.0、TLS1.1 的情况。

    要解决它, 要么使用“smtp-legacy.office365.com” 要么 通过

    配置客户端使用TLS1.2
    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    

    阅读来自 Microsoft 技术社区的 this 文章了解更多详情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      • 1970-01-01
      • 2018-01-31
      相关资源
      最近更新 更多