I am building an email sending service (lambda, Nodejs) which will send email to list of addresses at the same time.
Because of requirement: each address receives a different email content, I cannot send multiple emails in one request, but one by one.
_array = ... // list of address + html content, > 10000 records
for (var i = 0; i < _array.length; i++) {
var params = {
Destination: {/* required */
ToAddresses: [_array[i].email]
},
Message: {/* required */
Body: { /* required */
Html: {
Data: _array[i].html,
Charset: 'UTF-8'
},
},
Subject: { /* required */
Data: 'Your order detail', /* required */
Charset: 'UTF-8'
}
},
Source: "mytestemail@email.com"
}
let send = await ses.sendEmail(params).promise();
}
Currently, I don't have that big data to test, but I tested with 100-200 emails, it's working, and take 15-40 secs to complete sending emails. Mathematically, 10000 need more than 25 mins to complete the task. Therefore, this approach is not scalable, because of lambda timeout limit at 15 mins
Any better approach or suggestion is appreciated.
Edit:
The solution from @Thales Minussi is awesome, I implemented it and it's working. I marked it as an answer, but still, I welcome all best practices address this issue. Share, learn, and code happily