Search code examples
ajaxamazon-web-servicesemailcronamazon-ses

Email batches via AWS SES, ideas?


I have an SaaS application where each paying customer may have thousands of members they may want to send emails to every now and then.

For now, simple BCC sending via AWS SES have done the trick, but now I am looking at sending personalized emails so I must be able to send the emails one by one.

SES does not have any queue system as per my knowledge, you must make an API call per email. In short, it takes forever to send a batch (my limit is 14 per second), and the user cannot close the page while it is executing (even AJAX calls stop executing if you leave the page, am I right?).

I was thinking of building a system where I store the emails in a database table and then either:

1) Use a CRON that executes every 5 seconds or so, grab a few emails and send them.

2) Execute an AJAX script each 5 seconds that grabs the emails for said logged in customer in a batch ONLY and send them out, but again, if the customer logs out while it executes chances are that specific a batch is interrupted (the remaining ones would still keep sending the next time the customer logs in).

Does any have any better ideas? Or, which of the two above would be preferred?


Solution

  • You should use templates and the SendBulkTemplatedEmail endpoint that AWS introduced a few months ago: https://aws.amazon.com/blogs/ses/introducing-email-templates-and-bulk-sending/.

    That way you can send up to 50 personalized emails with a single SES API call. So 700 with 14 calls.

    You shouldn't consider queuing them up in a user's browser and sending them by making a series of AJAX requests though. You should only send one Ajax request to start a job. In most server-side languages (any I can think of) you can respond to an HTTP request and still continue doing processing after responding. You can also implement a progress checker in a multitude of ways.