It's perfectly fine to do it like this. Like you said, each email is unique so you can't bulk send them to multiple users at once!
Robust Mass Email with Mandrill
I need to send a monthly custom email to all of my users. My mail in Laravel 5.1 is configured to use the Mandrill API (loving Mandrill so far). I looked into batch email with Mandrill API, and its "merge vars" but my emails are really custom per user, so I cant use that or something like MailChimp because as far as I can tell, the body of the email would have to be the same, or in the case of merge vars very similar.
I do have a Beanstalkd queue system available and working via Forge. Would it be as simple as this (which would result in potentially thousands of HTTP requests to the Mandrill API) or is there a better way? :
User::chunk(200, function ($users) {
foreach ($users as $user) {
Mail:queue(...)
}
});
Thanks for any ideas or experience you may share :)
Just be careful when sending this amount of emails through Mandrill that you don't get yourself a bad reputation and throttled due to non deliveries, rejected mail and spam reports.
That probably depends on how recently you acquired the emails in your system and how many emails you'd send from the start. I'd probably recommend building the number of emails up over time, rather than starting to send so many emails suddenly. And try to spread the emails out over as much time as possible.
How have you set the beanstalk queue up? Would you queue the potentially thousands of emails all at once? And just let them send as quick as they can? That would possibly lead to the bad rep and being throttled.
It might be worth setting up a cron job to call a custom artisan command every x minutes. This command would then push a certain number of emails to the queue. Should reduce the likelihood of it causing problems but doesn't mitigate the risk entirely. I'd keep a careful eye on Mandrill and the stats it provides.
EDIT: You'll need to store the last position (userid) somewhere so that your artisan command knows which emails to queue next. That could either be in the database or in the cache, as an example.
Please or to participate in this conversation.