asp.net – Amazon SES停止工作

前端之家收集整理的这篇文章主要介绍了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中提到,导致您看到的错误

When I do not dispose of the SmtpClient,I get the error…

‘Service not available,closing transmission channel. The server
response was: Timeout waiting for data from client.’

这实际上是间歇性问题的一个很好的解释,即根据执行的代码路径,这个问题可能会触发到Amazon SES挂起的SMTP连接,这显然是通过切换到另一个端口来解决,这意味着连接被重置 – 这就是SmtpClient.Dispose Method确保:

Sends a QUIT message to the SMTP server,gracefully ends the TCP
connection,and releases all resources used by the current instance of
the 07003 class.

因此,如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

You are sending to Amazon SES from an Amazon EC2 instance via port 25
and you cannot reach your Amazon SES sending limits or you are
receiving time outs
— Amazon SES EC2 imposes default sending limits on
email sent via port 25 and throttles outbound connections if you
attempt to exceed those limits. To remove these limits,submit a
07009. You can also connect to
Amazon SES via port 465 or port 587,neither of which is throttled.

因此,我将删除端口25的测试/切换场景,并使用端口465/587,以避免虚假的引导(引用你也可以要求得到这个限制,但是需要几个小时,端口25似乎最好避免在第一位) – 有点不幸的是,几个官方的亚马逊SES样品正在使用端口25,甚至没有提到这个容易触发的问题确实.

原文链接:https://www.f2er.com/aspnet/250740.html

猜你在找的asp.Net相关文章