c# - Office 365 SMTP 开始触发 net_io_connectionclosed

标签 c# asp.net smtp office365

不久前,我将我的 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 上抛出的。

最佳答案

在我们的例子中,我们已经在使用 smtp.office365.com 端点,但突然间我们开始在我们的一台机器上接收到 net_io_connectionclosed,而相同的代码在别人身上完美地工作。调查表明,这些机器将 smtp.office365.com 解析为不同的 IP 地址,看起来其中一台服务器出现了异常。

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

Recently, we started rejecting a percentage of connections to smtp.office365.com that uses TLS1.0/1.1 for SMTP AUTH (complete disablement will start early 2022).

仅此而已。 Switching to TLS 1.2修复了整个问题。

关于c# - Office 365 SMTP 开始触发 net_io_connectionclosed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28362132/

相关文章:

c# - __EVENTTARGET 在按钮点击回发时为空

http - MIME 和内容类型之间有区别吗?

java - 通过中继服务器用 Java 发送电子邮件

C# 随机 BigInt 生成器

c# - 处理文件属性 C#

c# - 使用参数调用事件处理程序

asp.net - 是否有等效于 IIS 的 mod_pagespeed Apache 模块?

asp.net - 播放嵌入在网站上的youtube时参数无效

python - 如何设置Airflow发送邮件?

c# - Include 中使用的 Lambda 表达式无效。 EF6,导航属性