System.Net.Mail:net_io_connectionclosed
廣告:
“/”應(yīng)用程序中的服務(wù)器錯(cuò)誤。
無(wú)法從傳輸連接中讀取數(shù)據(jù): net_io_connectionclosed。
說(shuō)明: 執(zhí)行當(dāng)前 Web 請(qǐng)求期間,出現(xiàn)未處理的異常。請(qǐng)檢查堆棧跟蹤信息,以了解有關(guān)該錯(cuò)誤以及代碼中導(dǎo)致錯(cuò)誤的出處的詳細(xì)信息。
異常詳細(xì)信息: System.IO.IOException: 無(wú)法從傳輸連接中讀取數(shù)據(jù): net_io_connectionclosed。
源錯(cuò)誤:
執(zhí)行當(dāng)前 Web 請(qǐng)求期間生成了未處理的異常?梢允褂孟旅娴漠惓6褩8櫺畔⒋_定有關(guān)異常原因和發(fā)生位置的信息。
堆棧跟蹤:
[IOException: 無(wú)法從傳輸連接中讀取數(shù)據(jù): net_io_connectionclosed。]
System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) +1927397
System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +269
System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +45
System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +794
System.Net.Mail.SmtpClient.Send(MailMessage message) +1496
[SmtpException: 發(fā)送郵件失敗。]
Mvccom.Email.NetSendMail(String frmAddress, String fromname, String password, String toAddress, String copyTo, String mailSubject, String mailContent, String mailserver, Boolean ssl, Int32 smtpport) in E:\aspnet2.0\nyweb_jia\Mvccom\Email.cs:204
Mvccom.Email.SendMail(String subjectStr, String bodyStr, String fromName, String toEmail) in E:\aspnet2.0\nyweb_jia\Mvccom\Email.cs:16
Nydesign.Controllers.OrderController.Save() in E:\aspnet2.0\nyweb_jia\Nydesign\Controllers\OrderController.cs:252
lambda_method(ExecutionScope , ControllerBase , Object[] ) +30
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +236
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +31
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +85
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +655491
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +655491
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +288
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +658100
System.Web.Mvc.Controller.ExecuteCore() +125
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +48
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +15
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +85
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +454
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263
版本信息: Microsoft .NET Framework 版本:2.0.50727.8793; ASP.NET 版本:2.0.50727.8762
首先,簡(jiǎn)單回答如下:
.NETSmtpClient只支持通過(guò)STARTTLS加密。如果EnableSsl設(shè)置了標(biāo)志,服務(wù)器必須使用STARTTLS響應(yīng)Ehlo,否則會(huì)引發(fā)異常。
第二,為那些在未來(lái)偶然發(fā)現(xiàn)這個(gè)問(wèn)題的人提供一個(gè)快速的SMTP歷史教訓(xùn):
回到當(dāng)時(shí),當(dāng)服務(wù)還想提供加密時(shí),他們被分配了一個(gè)不同的端口號(hào),并且在這個(gè)端口號(hào)上,他們立即啟動(dòng)了一個(gè)SSL連接。隨著時(shí)間的推移,他們意識(shí)到為一個(gè)服務(wù)浪費(fèi)兩個(gè)端口號(hào)是愚蠢的,他們?yōu)榉⻊?wù)設(shè)計(jì)了一種方法,允許使用STARTTLS在同一個(gè)端口上進(jìn)行明文和加密。通信將開始使用明文,然后使用STARTTLS命令升級(jí)到加密連接。STARTTLS成為SMTP加密的標(biāo)準(zhǔn)。不幸的是,與實(shí)現(xiàn)新標(biāo)準(zhǔn)時(shí)一樣,與所有客戶端和服務(wù)器都存在大量的兼容性。
在我的示例中,我的用戶試圖將軟件連接到強(qiáng)制立即使用SSL連接的服務(wù)器,這是Microsoft在.NET中不支持的遺留方法。
解決方法:system.web.mail 用465端口,system.net.mail用587端口
廣告: