Unable to send e-mail from within custom Symfony2 command but can from elsewhere in app

前端 未结 3 605
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 10:45

I have written a custom console command to query my database, produce a report and e-mail it to an address; however I can not seem to successfully send the e-mail. I can sen

3条回答
  •  失恋的感觉
    2020-12-30 11:20

    Just add this to the end of your execute action:

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

提交回复
热议问题