‪TYPO3CMS  9.5
SendEmailCommand.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Input\InputOption;
21 use Symfony\Component\Console\Output\OutputInterface;
22 use Symfony\Component\Console\Style\SymfonyStyle;
25 
33 class ‪SendEmailCommand extends Command
34 {
38  protected function ‪configure()
39  {
40  $this
41  ->setDescription('Sends emails from the spool')
42  ->addOption('message-limit', null, InputOption::VALUE_REQUIRED, 'The maximum number of messages to send.')
43  ->addOption('time-limit', null, InputOption::VALUE_REQUIRED, 'The time limit for sending messages (in seconds).')
44  ->addOption('recover-timeout', null, InputOption::VALUE_REQUIRED, 'The timeout for recovering messages that have taken too long to send (in seconds).');
45  }
46 
54  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
55  {
56  $io = new SymfonyStyle($input, ‪$output);
57 
58  $mailer = $this->‪getMailer();
59 
60  $transport = $mailer->getTransport();
61  if ($transport instanceof \Swift_Transport_SpoolTransport) {
62  $spool = $transport->getSpool();
63  if ($spool instanceof \Swift_ConfigurableSpool) {
64  $spool->setMessageLimit((int)$input->getOption('message-limit'));
65  $spool->setTimeLimit((int)$input->getOption('time-limit'));
66  }
67  if ($spool instanceof \Swift_FileSpool) {
68  $recoverTimeout = (int)$input->getOption('recover-timeout');
69  if ($recoverTimeout) {
70  $spool->recover($recoverTimeout);
71  } else {
72  $spool->recover();
73  }
74  }
75  $sent = $spool->flushQueue($mailer->getRealTransport());
76  $io->comment($sent . ' emails sent');
77  } else {
78  $io->error('The Mailer Transport is not set to "spool".');
79  }
80  }
81 
87  protected function ‪getMailer(): ‪Mailer
88  {
89  return GeneralUtility::makeInstance(Mailer::class);
90  }
91 }
‪TYPO3\CMS\Core\Command\SendEmailCommand
Definition: SendEmailCommand.php:34
‪TYPO3\CMS\Core\Command\SendEmailCommand\execute
‪int void null execute(InputInterface $input, OutputInterface $output)
Definition: SendEmailCommand.php:54
‪TYPO3\CMS\Core\Command\SendEmailCommand\configure
‪configure()
Definition: SendEmailCommand.php:38
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:29
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Core\Command
Definition: DumpAutoloadCommand.php:3
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Command\SendEmailCommand\getMailer
‪Mailer getMailer()
Definition: SendEmailCommand.php:87