AfterMailerInitializationEvent
The PSR-14 event \TYPO3\
is fired once a new mailer is instantiated with specific transport
settings. So it is possible to add custom mailing settings.
Example
An example listener, which hooks into the Mailer API to modify mailer settings to not send any emails ("null mailer"), could look like this:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Mail\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Mail\Event\AfterMailerInitializationEvent;
#[AsEventListener(
identifier: 'my-extension/after-mailer-initialization',
)]
final readonly class MyEventListener
{
public function __invoke(AfterMailerInitializationEvent $event): void
{
$event->getMailer()->injectMailSettings(['transport' => 'null']);
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.