AfterMailerSentMessageEvent¶
New in version 12.0.
This event 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:
MyVendor\MyExtension\EventListener\MailerSentMessageEventListener:
tags:
- name: event.listener
identifier: 'my-extension/process-sent-message'
method: 'processSentMessage'
The corresponding event listener class:
namespace MyVendor\MyExtension\EventListener;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Mail\Event\AfterMailerSentMessageEvent;
use TYPO3\CMS\Core\Mail\Mailer;
final class MailerSentMessageEventListener implements LoggerInterface
{
use LoggerAwareTrait;
public function processSentMessage(AfterMailerSentMessageEvent $event): void
{
$mailer = $event->getMailer();
if ($mailer instanceof Mailer) {
$sentMessage = $mailer->getSentMessage();
if ($sentMessage !== null) {
$this->logger->debug($sentMessage->getDebug());
}
}
}
}
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()¶
- Return type
Symfony\Component\Mailer\MailerInterface