2
votes

I am trying to send a weekly newsletter to about 17.000 people, based on Symfony2 and Swiftmailer. My current problem is, that I wrote a command for the console. I can call it for example by "php app/console mail:send --newsletter 0 500". The last two numbers are additional variables for the offset and the amount of recipients which should be selected at once. What I normally would like to do is to use a cronjob, that calls this command once, in this case with the offset of 0 and the amount of 20.000 to get all recipients. This isn't working or atleast the amount of mails is just to big. My first test was to send these mails by myself, so that I can see what's happening. The script never ended until I reached the amount of 500 or less. Is this normal?

Here is what I do:

  1. get users from the DB
  2. find articles from the DB I want to send in this newsletter
  3. run over all recipients, generate a new message by $message = \Swift_Message::newInstance()... and call $this->mailer->send($message);
  4. finally flush the queue by doing this:

    $spool = $this->mailer->getTransport()->getSpool();
    $transport = $this->getContainer()->get('swiftmailer.transport.real');
    $spool->flushQueue($transport);
    

About what I am not sure is how I should send all these mails now. Is it wrong to just call a shell script with a cronjob, that iterates this command by changing the the offset, so that only 500 mails at once will be generated? Or what is the right way to do this? Or am I doing it totally wrong and that's why I cant send more than 500? With 1000 for example the console just doesn't react anymore until I cancel the script. I already tried to start it in the background, but it seemed that the script just wasn't working at all... and no error or something like that occured, just no reaction.

Edit: Or is it even better to use a specific mailbox to send all these mails instead of using PHP with the mail()-function, which is probably also used in the SwiftMailer?

Thank you very much for your help! Manuel

1
Its normal to execute a queue with over 500 mails not at once. Most mail server will deny delivery messages, when too much from same source come. I have an project in Symfony 1.4 and we send 500 mails in ten minutes, that works great.falsch
So you have a delay between your calls? But you have 1 cronjob oder many cronjobs with this delay of 10 mins?Manuel

1 Answers

0
votes

we have a similar scenario and we decided to use sonata notification bundle + RabbitMQ. You can create a console command to generate all the information and send it to RabbitMQ, and then with the sonata bundle you can create a consume thah manage the queue to send groups of emails.
If you need help with it's configurations here we are