AfterMailerInitializationEvent

The PSR-14 event \TYPO3\CMS\Core\Mail\Event\AfterMailerInitializationEvent 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:

EXT:my_extension/Classes/Mail/EventListener/MyEventListener.php
<?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']);
    }
}
Copied!

New in version 13.0

API

class AfterMailerInitializationEvent
Fully qualified name
\TYPO3\CMS\Core\Mail\Event\AfterMailerInitializationEvent

This event is fired once a new Mailer is instantiated with specific transport settings.

So it is possible to add custom mailing settings.

getMailer ( )
Returns
\Symfony\Component\Mailer\MailerInterface