+-

前段时间我已经将我的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上似乎抛出异常.
最佳答案
同样的问题始于2月8日我公司.这个问题会随之而去.
我认为解决问题的方法是更改SMTP服务器地址.
我们原来的SMTP服务器地址是podxxxxx.outlook.com,大部分时间仍然有效.我在门户网站上检查了当前的O365 SMTP服务器地址,它应该是smtp.office365.com.
我改变了我的配置指向这个新地址,问题似乎消失了.我的日志显示更改后的最后24小时没有错误.
如果错误再次发生,我会更新.
点击查看更多相关文章
转载注明原文:c# – Office 365 SMTP开始触发net_io_connectionclosed - 乐贴网