AfterMailerSentMessageEvent

New in version 12.0

The PSR-14 event \TYPO3\CMS\Core\Mail\Event\AfterMailerSentMessageEvent is dispatched as soon as the message has been sent via the corresponding \Symfony\Component\Mailer\Transport\TransportInterface. It receives the current mailer instance, which depends on the implementation - usually \TYPO3\CMS\Core\Mail\Mailer. It contains the \Symfony\Component\Mailer\SentMessage object, which can be retrieved using the getSentMessage() method.

Example

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\Mail\EventListener\MyEventListener:
    tags:
      - name: event.listener
        identifier: 'my-extension/process-sent-message'
Copied!

Read how to configure dependency injection in extensions.

The corresponding event listener class:

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

API

class \TYPO3\CMS\Core\Mail\Event\ AfterMailerSentMessageEvent

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.

getMailer ( )
returntype

Symfony\Component\Mailer\MailerInterface