* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\SwiftmailerBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; /** * Send Emails from the spool. * * @author Fabien Potencier * @author Clément JOBEILI */ class SendEmailCommand extends ContainerAwareCommand { /** * @see Command */ protected function configure() { $this ->setName('swiftmailer:spool:send') ->setDescription('Sends emails from the spool') ->addOption('message-limit', 0, InputOption::VALUE_OPTIONAL, 'The maximum number of messages to send.') ->addOption('time-limit', 0, InputOption::VALUE_OPTIONAL, 'The time limit for sending messages (in seconds).') ->addOption('recover-timeout', 0, InputOption::VALUE_OPTIONAL, 'The timeout for recovering messages that have taken too long to send (in seconds).') ->setHelp(<<swiftmailer:spool:send command sends all emails from the spool. php app/console swiftmailer:spool:send --message-limit=10 --time-limit=10 --recover-timeout=900 EOF ) ; } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $mailer = $this->getContainer()->get('mailer'); $transport = $mailer->getTransport(); if ($transport instanceof \Swift_Transport_SpoolTransport) { $spool = $transport->getSpool(); if ($spool instanceof \Swift_ConfigurableSpool) { $spool->setMessageLimit($input->getOption('message-limit')); $spool->setTimeLimit($input->getOption('time-limit')); } if ($spool instanceof \Swift_FileSpool) { if (null !== $input->getOption('recover-timeout')) { $spool->recover($input->getOption('recover-timeout')); } else { $spool->recover(); } } $sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real')); $output->writeln(sprintf('sent %s emails', $sent)); } } }