Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Office 365 SMTP开始启动网络io连接已关闭_C#_Asp.net_Smtp_Office365 - Fatal编程技术网

C# Office 365 SMTP开始启动网络io连接已关闭

C# Office 365 SMTP开始启动网络io连接已关闭,c#,asp.net,smtp,office365,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,

不久前,我将我的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();

异常似乎是在处置上抛出的

这一问题于2月8日在我的公司开始出现。这个问题会来来去去去,没有规律可循

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

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

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


如果错误再次发生,我将更新此信息。

将pod51014.outlook.com替换为smtp.office365.com-希望一切顺利。与您的问题无关,但我会从您的电子邮件发送代码中删除对
ConfigurationManager
的呼叫。我将编写一个发送电子邮件的通用方法(例如名称:
sendmail
),并将这些值作为变量传递。将对
ConfigurationManager
的调用放在调用
sendmail
的方法中。好。。。实际上,我会将我的
ConfigurationManager
调用封装在一个特定于返回配置值的规范化类中,这样我就可以像variable
MyAppConfigClass.SmtpServer