【发布时间】:2015-12-17 06:54:03
【问题描述】:
我已经创建了 azure sendgrid 帐户。实际上,我可以使用我的 sendgrid 凭据在 azureVM 中发送邮件,并且我们在 azure 门户中发布了该站点。在 azure webapp 中,相同的电子邮件发送失败,错误如下:
“无法从传输连接中读取数据:net_io_connectionclosed。” 我用来发送邮件的 C# 代码:
起初我尝试使用 smtp
var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
var mail = new MailMessage();
var smtpServer = new SmtpClient(smtpSection.Network.Host);
mail.From = new MailAddress(smtpSection.Network.UserName);
mail.From = new MailAddress("john@example.com", "John Smith");
mail.To.Add(userId);
mail.Subject = subject;
mail.Body = body;
smtpServer.Port = smtpSection.Network.Port;
smtpServer.Credentials = new System.Net.NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password);
smtpServer.EnableSsl = false;
smtpServer.Send(mail);
网页配置内容:
<network defaultCredentials="true" host="smtp.sendgrid.net" port="25" userName="mysendgriduserid@azure.com" password="mysendgridpassword" />
它在 azure webapp 中失败,但在 azureVM 中运行良好。然后我尝试使用下面的 sendgrid api:
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo(userId);
myMessage.From = new MailAddress("john@example.com", "John Smith");
myMessage.Subject = subject;
myMessage.Text = body;
var transportWeb = new Web("myapikey");
transportWeb.DeliverAsync(myMessage);
这在 azure webapp 中也失败了,但在 azureVM 中运行良好。两者都显示与图像中相同的错误。
我完全一无所知。请帮助我摆脱这个错误。
谢谢。
我很抱歉。我无法上传图片。我只是分享图像中的堆栈跟踪:
Server Error in '/' Application.
Unable to read data from the transport connection: net_io_connectionclosed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IOException: Unable to read data from the transport connection: net_io_connectionclosed.]
System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) +1829453
System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +227
System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +16
System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) +54
System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) +36
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) +88
System.Net.Mail.SmtpClient.Send(MailMessage message) +1661
[SmtpException: Failure sending mail.]
Dme.Application.Repositories.<Dme-Application-Repositories-IIdentityRepository-SendEmailAsync>d__22.MoveNext() +259
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
Dme.Application.Services.<Dme-Shared-Contracts-IIdentityService-CreateOrUpdateUserAsync>d__14.MoveNext() +5421
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
Dme.Web.UI.Areas.Admin.Controllers.<SaveOrUpdate>d__13.MoveNext() +962
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +50
System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +225
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.114.0
【问题讨论】:
-
你能提供你说的图片吗?
-
你检查 25 端口打开了吗?
标签: c# email azure azure-web-app-service sendgrid