BeforeMailerSentMessageEvent
New in version 12.0
The PSR-14 event \TYPO3\
is dispatched before the message is sent by the mailer and can be
used to manipulate the \Symfony\
and the
\Symfony\
. Usually a
\Symfony\
or \TYPO3\
instance is given as Raw
. Additionally the mailer instance is
given, which depends on the implementation - usually
\TYPO3\
. It contains the
\Symfony\
object, which can be retrieved using
the get
method.
Example
This event adds an additional BCC receiver right before the mail is sent:
<?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);
}
}
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 BeforeMailerSentMessageEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Mail\ Event\ Before Mailer Sent Message Event
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.