简体   繁体   中英

Efficient newsletter with Symfony2 and Swiftmailer

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM