Sending Bulk Email with AWS SES
My current setup is as follows:
I have a list of clients to send bulk email to. In my software I have an option to send immediately or schedule a time of when it should be sent. I save the email details in my database with a send time and date and then have setup a schedule in the console kernel.php to check that table and if there are emails due to be sent then they will be sent.
Firstly I am confirming their is no need to queue this to SQS as basically my setup is essentially queuing it (Unless there are benefits I am not aware of)
Now I can see that there are two options:
- I loop through the students and send individually to SES.
- Send through AWS SDK creating a template and sending the emails in one go.
With option 1, I have a limit of 14 emails per second with SES so I have come up with this.
$i=0;
foreach($clients as $client){
// send email code
if(($i++ % 10) == 0) {
sleep(1);
}
}
I believe this will only send 10 per second.
With option 2 I have a limit of 50 email addresses with each call (I think thats the limit) so need to send in batches of 50 which would be fairly straightforward.
So my question is which is better and if I use option 1 is my code correct or is there a better way of writing it?
Or am I doing it all wrong and there is a better way!!
For anyone else that wants an answer to this the solution is as follows:
If you are sending emails and dealing with any dynamic data yourself just use option 1 and loop over each email address and send to the SES API individually setting a delay in the script on every send. The following should send 10 every second.
foreach($clients as $client) {
// send email code
usleep(100000);
}
If you want to personalise the recipient name in the email body then use the template option and send with a maximum of 50 addresses at a time as that is the limit with each API call.
Please or to participate in this conversation.