title: Amazon SES Stops Working
body: <p>I set up Amazon SES and it initially worked for a few hours, then all of a sudden stopped. All of the e-mails I'm sending as, and our domain, have been verified. We are no sending bulk e-mails - only a few hundred per day. Whenever I make changes to the web.config it seems to allow it work again for another 2-3 hours. For example, It stopped working so I switched port 587 to 25, and it began working for 2-3 hours, then stopped. Then I switched back to 587 and the same thing happened. Once it stops working it doesn't ever seem to start again on its own. It is running on two load balanced servers, asp.net framework v2.0, IIS 7.5. Here is the code I'm using:</p>
  
  <p>web.config:</p>
  
  <pre><code>&lt;system.net&gt;
    &lt;mailSettings&gt;
      &lt;smtp deliveryMethod="Network" from="no-reply@ourdomain.com"&gt;
        &lt;network defaultCredentials="false" host="email-smtp.us-east-1.amazonaws.com" userName="***" password="***" port="587" /&gt;
      &lt;/smtp&gt;
    &lt;/mailSettings&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>c# code:</p>
  
  <pre><code>var smtpClient = new SmtpClient() { EnableSsl = true };
  
  var mailMessage =
      new MailMessage(fromAddress, toAddress, subject, body)
      {
          IsBodyHtml = true
      };
  
  smtpClient.Send(mailMessage);
  </code></pre>
  
  <p>Here are the two errors I've been receiving:</p>
  
  <pre><code>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 &lt;smtpMail&gt; section is valid. ---&gt; System.Net.Mail.SmtpException: Failure sending mail. ---&gt; 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 offset, Int32 size)
     at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, 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)
  </code></pre>
  
  <hr>
  
  <pre><code>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 &lt;smtpMail&gt; section is valid. ---&gt; 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&amp; 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 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)
  </code></pre>
  
  <p>I tried to get help on the Amazon forums but haven't had any luck. It seems like something is interfering with the connection but I don't know what. Any ideas? Thanks.</p>