‪TYPO3CMS  10.4
SendEmailCommand.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Symfony\Component\Console\Command\Command;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Input\InputOption;
23 use Symfony\Component\Console\Output\OutputInterface;
24 use Symfony\Component\Console\Style\SymfonyStyle;
29 
37 class ‪SendEmailCommand extends Command
38 {
42  protected function ‪configure()
43  {
44  $this
45  ->setDescription('Sends emails from the spool')
46  ->addOption('message-limit', null, InputOption::VALUE_REQUIRED, 'The maximum number of messages to send.')
47  ->addOption('time-limit', null, InputOption::VALUE_REQUIRED, 'The time limit for sending messages (in seconds).')
48  ->addOption('recover-timeout', null, InputOption::VALUE_REQUIRED, 'The timeout for recovering messages that have taken too long to send (in seconds).')
49  ->setAliases(['swiftmailer:spool:send']);
50  }
51 
59  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
60  {
61  $io = new SymfonyStyle($input, ‪$output);
62 
63  $mailer = $this->‪getMailer();
64 
65  $transport = $mailer->getTransport();
66  if ($transport instanceof ‪DelayedTransportInterface) {
67  if ($transport instanceof ‪FileSpool) {
68  $transport->setMessageLimit((int)$input->getOption('message-limit'));
69  $transport->setTimeLimit((int)$input->getOption('time-limit'));
70  $recoverTimeout = (int)$input->getOption('recover-timeout');
71  if ($recoverTimeout) {
72  $transport->recover($recoverTimeout);
73  } else {
74  $transport->recover();
75  }
76  }
77  $sent = $transport->flushQueue($mailer->getRealTransport());
78  $io->comment($sent . ' emails sent');
79  return 0;
80  }
81  $io->error('The Mailer Transport is not set to "spool".');
82 
83  return 1;
84  }
85 
91  protected function ‪getMailer(): ‪Mailer
92  {
93  return GeneralUtility::makeInstance(Mailer::class);
94  }
95 }
‪TYPO3\CMS\Core\Command\SendEmailCommand
Definition: SendEmailCommand.php:38
‪TYPO3\CMS\Core\Mail\FileSpool
Definition: FileSpool.php:40
‪TYPO3\CMS\Core\Command\SendEmailCommand\configure
‪configure()
Definition: SendEmailCommand.php:42
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:38
‪TYPO3\CMS\Core\Mail\DelayedTransportInterface
Definition: DelayedTransportInterface.php:26
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Command\SendEmailCommand\execute
‪int execute(InputInterface $input, OutputInterface $output)
Definition: SendEmailCommand.php:59
‪TYPO3\CMS\Core\Command
Definition: DumpAutoloadCommand.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Command\SendEmailCommand\getMailer
‪Mailer getMailer()
Definition: SendEmailCommand.php:91