Amazon SES remote error: tls: user canceled, 421 Connection closed by server. Too many messages in one session

0

I've been using SES to send 2-3k emails per day without issue. When I increased it to 50k+ I started getting a bunch of these errors.

421 Connection closed by server. Too many messages in one session
remote error: tls: user canceled

Two different errors, but they both consistently occur at about the same rate.

My SES limits are well above the settings I'm using. My limit is 500k/24hrs, 120/s. I'm sending at 100/s. I tried lowering the send rate to 50/s and I still get the errors.

I thought it might be the recipient email server (gmail, hotmail, etc.) rejecting my emails, but looking at the subscribers it failed for, they're very diverse. IE: they're not all from gmail or hotmail, but many providers.

I found a discussion https://stackoverflow.com/questions/49111453/sending-email-with-aws-ses-via-smtp-error-421 which says it might be solved by changing the port from 465 to 587. I'm considering trying that, but many sources, including Amazon https://docs.aws.amazon.com/ses/latest/dg/smtp-connect.html, say that 465 is more secure.

EDIT: I tried STARTTLS 587 but got the same errors.

User21
asked a month ago103 views
1 Answer
1
Accepted Answer

Hi THere

Can you provide some details on how your application is sending mail? Is it using some sort of keep alive to hold a connection open to the SMTP server? If so, you might want to try limiting that. Also, do you have any retry/backoff in your application code?

See https://docs.aws.amazon.com/ses/latest/dg/troubleshoot-smtp.html#troubleshoot-smtp-response-codes

You should retry SMTP requests that receive 400 errors. We recommend that you implement a system that retries requests with progressively longer wait times (for example, wait 5 seconds before retrying, then wait 10 seconds, and then wait 30 seconds). If the third retry doesn't succeed, wait 20 minutes, and then repeat the process. To see an example of an implementation that uses an exponential retry policy, see How to handle a "Throttling - Maximum sending rate exceeded" error on the AWS Messaging and Targeting Blog.

profile pictureAWS
EXPERT
Matt-B
answered a month ago
  • Thank you Matt! I am using https://listmonk.app/. I will refer the developer to your comment.

  • I believe you need to reduce the concurrency. One other thing to check is the application server you are sending from. The OS or other factors could be limiting the number of network connections causing a timeout. Is it possible to add more resources to your application server and see if it helps?

    Also, it looks like you can use listmonk-messenger to interface with the SES API instead of using the SMTP endpoint of SES, might be worth looking in to. See https://github.com/joeirimpan/listmonk-messenger

  • Per the help text at https://demo.listmonk.app/admin/settings

    Maximum number of messages to be sent out per second per worker in a second. If concurrency = 10 and message_rate = 10, then up to 10x10=100 messages may be pushed out every second. This, along with concurrency, should be tweaked to keep the net messages going out per second under the target message servers rate limits if any.

    My SES limit is 120/s so I had my concurrency and message_rate to 10x10. I tried lowering concurrency to 5 (5x10) and still got the errors. https://github.com/knadh/listmonk/issues/1717#issuecomment-2016906048

    My server usage is very low but I'll contact the provider to ask if this error may be due to a limit they have.

    I checked listmonk-messenger and SES API vs SMTP endpoint of SES, but it doesn't look like it would be worth the trouble https://github.com/joeirimpan/listmonk-messenger/issues/71.

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.

Guidelines for Answering Questions