Attention
TYPO3 v12 has reached end-of-life as of April 30th 2026 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v12 here: TYPO3 ELTS.
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
Registration of the event listener in the extension's Services.:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Mail\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/after-mailer-initialization'
Read how to configure dependency injection in extensions.
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\Mail\Event\AfterMailerInitializationEvent;
final class MyEventListener
{
public function __invoke(AfterMailerInitializationEvent $event): void
{
$event->getMailer()->injectMailSettings(['transport' => 'null']);
}
}