BeforeMailerSentMessageEvent

New in version 12.0

The PSR-14 event \TYPO3\CMS\Core\Mail\Event\BeforeMailerSentMessageEvent is dispatched before the message is sent by the mailer and can be used to manipulate the \Symfony\Component\Mime\RawMessage and the \Symfony\Component\Mailer\Envelope. Usually a \Symfony\Component\Mime\Email or \TYPO3\CMS\Core\Mail\FluidEmail instance is given as RawMessage. Additionally the mailer instance is given, which depends on the implementation - usually \TYPO3\CMS\Core\Mail\Mailer . It contains the \Symfony\Component\Mailer\Transport object, which can be retrieved using the getTransport() method.

Example

This event adds an additional BCC receiver right before the mail is sent:

EXT:my_extension/Classes/Mail/EventListener/AddMailMessageBcc.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Mail\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Mail\Event\BeforeMailerSentMessageEvent;
use TYPO3\CMS\Core\Mail\MailMessage;

#[AsEventListener(
    identifier: 'my-extension/add-mail-message-bcc',
)]
final readonly class AddMailMessageBcc
{
    public function __invoke(BeforeMailerSentMessageEvent $event): void
    {
        $message = $event->getMessage();
        if ($message instanceof MailMessage) {
            $message->addBcc('me@example.com');
        }
        $event->setMessage($message);
    }
}
Copied!

New in version 13.0

API

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

This event is fired before the Mailer has sent a message and allows listeners to manipulate the RawMessage and the Envelope.

Note: Usually TYPO3CMSCoreMailMailer is given to the event. This implementation allows to retrieve the TransportInterface using the getTransport() method.

getMessage ( )
Returns
\Symfony\Component\Mime\RawMessage
setMessage ( \Symfony\Component\Mime\RawMessage $message)
param $message

the message

getEnvelope ( )
Returns
?\Symfony\Component\Mailer\Envelope
setEnvelope ( ?\Symfony\Component\Mailer\Envelope $envelope = NULL)
param $envelope

the envelope, default: NULL

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