Skip to content

Intermittent AWS SES Email Sending Failures (Sporadic SMTP Connection Issues)

0

Hello,

I'm encountering intermittent failures when sending emails through AWS SES using SMTP in our web application. Most of the time, emails are sent without any problems, but we randomly experience failures.

Here are the different errors observed:

  • Connection attempts failing or being closed across multiple different host IPs:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message)
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

What we tried so far:

  • Rate limit issue? We’ve only logged one per sec. exceeded rate message several months ago, and haven't exceed the daily rate.
  • Attachment-related? The issue occurs whether emails include attachments or not.
  • Network issue? We have multiple stable datacenter networks, and the issue persists across all of them. Other services do not exhibit similar timeout issues. No packet loss or latency spikes observed.
  • Firewall issue? Emails usually send without issue, and no rules blocking the traffic.
  • Tried different ports: 25, 465 (current), and 587.
  • Tried different TLS settings: SSL, TLS 1.1, TLS 1.2, and 1.3.
  • Cross-checked with multiple network locations: Same issue occurs from different environments.

Questions:

  • Could AWS SES be throttling connections intermittently without logging it as rate limiting?
  • Are there any SES-specific logs we can check for SMTP failures?
  • Has anyone else experienced similar sporadic SES connection failures?
  • Any other debugging steps or AWS support paths we should explore?

Any insights would be greatly appreciated! Thanks in advance.

1 Answer
1

Based on the information provided, it appears you are experiencing intermittent connection issues with Amazon SES SMTP endpoints. This is a known issue that can occur due to the architecture of the SES SMTP service. Here are some insights and potential solutions:

  1. Long-lived connections: The Amazon SES SMTP endpoint operates on a fleet of EC2 instances behind an Elastic Load Balancer (ELB). To maintain system updates and fault tolerance, active EC2 instances are periodically terminated and replaced. This can cause existing connections to become invalid, resulting in the errors you're seeing.

  2. Connection management: To mitigate this issue, it's recommended to establish a new SMTP connection after sending a fixed number of messages or after a certain amount of time. You'll need to experiment to find the right thresholds based on your application's hosting environment and email submission patterns.

  3. Retry logic: Implement robust retry logic in your application to handle temporary connection failures. This is especially important for handling network errors that can cause dropped emails.

  4. IP address changes: The IP addresses for SES SMTP endpoints change frequently due to the load balancer setup. Instead of whitelisting specific IP addresses, it's recommended to whitelist the 'amazonses.com' domain.

  5. Throttling: While you mentioned not exceeding rate limits, SES might still be applying some form of throttling. However, this would typically be logged as a rate limit error.

  6. Logging: Unfortunately, there are no SES-specific logs for SMTP failures that you can directly access. You would need to rely on your application's logs and error handling.

  7. AWS Support: If the issue persists after implementing the above recommendations, it may be worth contacting AWS Support for further investigation, especially if you have an appropriate support plan.

To debug further:

  • Implement more detailed logging in your application to track the lifecycle of each SMTP connection.
  • Monitor the duration of your SMTP connections and see if failures correlate with longer-lived connections.
  • Consider implementing a connection pool with regular connection refresh to avoid using stale connections.

These sporadic connection issues are not uncommon with SES SMTP, and other users have reported similar experiences. The key is to design your application to be resilient to these intermittent failures through proper connection management and retry mechanisms.
Sources
Amazon SES SMTP issues - Amazon Simple Email Service
Amazon SES email sending errors - Amazon Simple Email Service

answered 9 months ago
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.