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
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Mail\EventListener;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Mail\Event\AfterMailerSentMessageEvent;
use TYPO3\CMS\Core\Mail\Mailer;
#[AsEventListener(
identifier: 'my-extension/process-sent-message',
)]
final readonly class MyEventListener
{
public function __construct(
private 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());
}
}
}
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.
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.