AfterMailerSentMessageEvent
New in version 12.0
The PSR-14 event \TYPO3\
is dispatched as soon as the message has been sent via the corresponding
\Symfony\
.
It receives the current mailer instance, which depends on the implementation -
usually \TYPO3\
. It contains the
\Symfony\
object, which can be retrieved
using the get
method.
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/process-sent-message'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Mail\EventListener;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Mail\Event\AfterMailerSentMessageEvent;
use TYPO3\CMS\Core\Mail\Mailer;
final class MyEventListener
{
public function __construct(
private readonly LoggerInterface $logger,
) {}
public function __invoke(AfterMailerSentMessageEvent $event): void
{
$mailer = $event->getMailer();
if (!$mailer instanceof Mailer) {
return;
}
$sentMessage = $mailer->getSentMessage();
if ($sentMessage !== null) {
$this->logger->debug($sentMessage->getDebug());
}
}
}
API
- class AfterMailerSentMessageEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Mail\ Event\ After Mailer Sent Message Event
This event is fired once a Mailer has sent a message and allows listeners to execute further code afterwards, depending on the result, e.g. the SentMessage.
Note: Usually TYPO3CMSCoreMailMailer is given to the event. This implementation allows to retrieve the SentMessage using the getSentMessage() method. Depending on the Transport, used to send the message, this might also be NULL.