asp.net – Amazon SES停止工作
我设立了亚马逊SES,最初工作了几个小时,然后突然停了.我发送的所有电子邮件和我们的域名已经过验证.我们不发送批量电子邮件 – 每天只有几百个.每当我更改web.config,它似乎允许它再工作2-3个小时.例如,它停止工作,所以我将端口587切换到25,并开始工作2-3个小时,然后停止.然后我转回到587,同样的事情发生了.一旦停止工作,它似乎不会再次重新开始.它运行在两个负载平衡的服务器上,asp.net框架v2.0,IIS 7.5.这是我使用的代码:
web.config中: <system.net> <mailSettings> <smtp deliveryMethod="Network" from="no-reply@ourdomain.com"> <network defaultCredentials="false" host="email-smtp.us-east-1.amazonaws.com" userName="***" password="***" port="587" /> </smtp> </mailSettings> </system.net> c#代码: var smtpClient = new SmtpClient() { EnableSsl = true }; var mailMessage = new MailMessage(fromAddress,toAddress,subject,body) { IsBodyHtml = true }; smtpClient.Send(mailMessage); 以下是我收到的两个错误: The following exception was thrown by the web event provider '(null)' in the application '/' (in an application lifetime a maximum of one exception will be logged per provider instance): System.Web.HttpException: Unable to send out an e-mail to the SMTP server. Please ensure that the server specified in the <smtpMail> section is valid. ---> System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream. at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer,Int32 offset,Int32 count) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer,Int32 readBytes,AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,Byte[] buffer,AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code,CleanupCode backoutCode,Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer,Int32 size) at System.Net.PooledStream.Write(Byte[] buffer,Int32 size) at System.Net.Mail.SmtpConnection.Flush() at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn) at System.Net.Mail.SmtpConnection.GetConnection(String host,Int32 port) at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at System.Web.Management.MailWebEventProvider.SendMail(MailMessage msg) --- End of inner exception stack trace --- at System.Web.Management.MailWebEventProvider.SendMail(MailMessage msg) at System.Web.Management.SimpleMailWebEventProvider.SendMessageInternal(WebBaseEventCollection events,Int32 notificationSequence,Int32 begin,DateTime lastFlush,Int32 discardedSinceLastFlush,Int32 eventsInBuffer,Int32 messageSequence,Int32 messagesInNotification,Int32 eventsInNotification,Int32 eventsLostDueToMessageLimit) at System.Web.Management.SimpleMailWebEventProvider.SendMessage(WebBaseEvent eventRaised) at *****.Global.SimpleMailWithSslWebEventProvider.ProcessEvent(WebBaseEvent raisedEvent) at System.Web.Management.WebBaseEvent.RaiseInternal(WebBaseEvent eventRaised,ArrayList firingRuleInfos,Int32 index0,Int32 index1) The following exception was thrown by the web event provider '(null)' in the application '/' (in an application lifetime a maximum of one exception will be logged per provider instance): System.Web.HttpException: Unable to send out an e-mail to the SMTP server. Please ensure that the server specified in the <smtpMail> section is valid. ---> System.Net.Mail.SmtpException: Service not available,closing transmission channel. The server response was: Timeout waiting for data from client. at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,String response) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,MailAddressCollection recipients,String deliveryNotify,SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at System.Web.Management.MailWebEventProvider.SendMail(MailMessage msg) --- End of inner exception stack trace --- at System.Web.Management.MailWebEventProvider.SendMail(MailMessage msg) at System.Web.Management.SimpleMailWebEventProvider.SendMessageInternal(WebBaseEventCollection events,Int32 index1) 我试图在亚马逊论坛上获得帮助,但没有任何运气.似乎有些东西干扰了连接,但我不知道什么.有任何想法吗?谢谢. 解决方法
这听起来像一个棘手的问题 – 我不是100%积极的,但是你似乎错过了处理SMTP客户端,这在
Sending email is often very slow after changing to VPC instance中提到,导致您看到的错误:
这实际上是间歇性问题的一个很好的解释,即根据执行的代码路径,这个问题可能会触发到Amazon SES挂起的SMTP连接,这显然是通过切换到另一个端口来解决,这意味着连接被重置 – 这就是SmtpClient.Dispose Method确保:
因此,如Getting Started with Amazon SES and .NET所示,适当的模式将是促进using Statement: String username = "SMTP-USERNAME"; // Replace with your SMTP username. String password = "SMTP-PASSWORD"; // Replace with your SMTP password. String host = "email-smtp.us-east-1.amazonaws.com"; int port = 25; using (var client = new System.Net.Mail.SmtpClient(host,port)) { client.Credentials = new System.Net.NetworkCredential(username,password); client.EnableSsl = true; client.Send ( "FROM@EXAMPLE.COM",// Replace with the sender address. "TO@EXAMPLE.COM",// Replace with the recipient address. "Testing Amazon SES through SMTP","This email was delivered through Amazon SES via the SMTP end point." ); } 请注意,该示例使用端口25,我强烈建议避免由于通常隐含的发送限制,请参阅下面的附录,了解各个Amazon EC2限制的详细信息. 祝你好运! 附录 Amazon EC2限制端口25 您可能会意识到这一点(我实际上不认为这是一个问题),但Amazon EC2通过端口25发送的电子邮件设置默认发送限制,并且如果您尝试超过使用Amazon SES时仍然适用的限制,见Amazon SES SMTP Issues:
因此,我将删除端口25的测试/切换场景,并使用端口465/587,以避免虚假的引导(引用你也可以要求得到这个限制,但是需要几个小时,端口25似乎最好避免在第一位) – 有点不幸的是,几个官方的亚马逊SES样品正在使用端口25,甚至没有提到这个容易触发的问题确实. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 如何发布站点从命令行与一些发布配置文件?
- ASP.NET MVC 使用Spring.NET 依赖注入
- asp.net-mvc – asp.net mvc我为我的模型使用了太多的类吗?
- 在ASP.NET MVC4中自定义错误消息MVC的无效DateTime
- 覆盖ASP.NET AJAX Control Toolkit的TabContainer控件中的默
- asp.net – 从Web API的承载令牌返回用户角色
- 从IIS上的ASP.NET Core应用程序请求超时
- asp.net – 使用asp:Button将参数传递给函数
- asp.net – 按顺序匹配的字段数量生成SQL顺序
- asp.net使用多线程更新UI
- ASP.NET Core 菜鸟之路:从Startup.cs说起
- asp.net – 如何在网格视图中设置样式模板字段(附
- 具有干净输出的ASP.NET HTML控件?
- .net-4.0 – 从3.5升级到ASP.net 4.0后登录失败
- asp.net – Sitecore – System.Security.Crypto
- asp.net – 在Visual Studio中查找CSS类引用的快
- 最接近Asp.net mvc3的Java MVC框架?
- asp.net – 用于网页的SQL Reporting Services查
- asp.net-mvc-3 – Ninject和OnePerRequestModule
- asp.net – 使用数据库或MSMQ进行排队?