/
SendEmailCommand.php
62 lines (54 loc) · 1.91 KB
/
SendEmailCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
/**
* Warmup the cache.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Clément JOBEILI <clement.jobeili@gmail.com>
*/
class SendEmailCommand extends Command
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('swiftmailer:spool:send')
->setDescription('Send all 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).')
->setHelp(<<<EOF
The <info>swiftmailer:spool:send</info> command send all emails from the spool.
EOF
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$mailer = $this->container->get('mailer');
$transport = $mailer->getTransport();
if ("Swift_Transport_SpoolTransport" === get_class($transport)) {
$spool = $transport->getSpool();
$spool->setMessageLimit($input->getOption('message-limit'));
$spool->setTimeLimit($input->getOption('time-limit'));
$sent = $spool->flushQueue($this->container->get('swiftmailer.transport.real'));
$output->writeln(sprintf('sent %s emails', $sent));
}
}
}