@@ -1419,7 +1419,7 @@ is sent::
14191419
14201420 class MailerSubscriber implements EventSubscriberInterface
14211421 {
1422- public static function getSubscribedEvents()
1422+ public static function getSubscribedEvents(): array
14231423 {
14241424 return [
14251425 MessageEvent::class => 'onMessage',
@@ -1437,6 +1437,65 @@ is sent::
14371437 }
14381438 }
14391439
1440+ SentMessageEvent
1441+ ~~~~~~~~~~~~
1442+
1443+ ``SentMessageEvent `` it allows acting on the :class: `Symfony\\ Component\\ Mailer\\ SentMessage `::
1444+
1445+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1446+ use Symfony\Component\Mailer\Event\SentMessageEvent;
1447+ use Symfony\Component\Mailer\SentMessage;
1448+
1449+ class MailerSubscriber implements EventSubscriberInterface
1450+ {
1451+ public static function getSubscribedEvents(): array
1452+ {
1453+ return [
1454+ SentMessageEvent::class => 'onMessage',
1455+ ];
1456+ }
1457+
1458+ public function onMessage(SentMessageEvent $event): void
1459+ {
1460+ $message = $event->getMessage();
1461+ if (!$message instanceof SentMessage) {
1462+ return;
1463+ }
1464+
1465+ // do something with the message
1466+ }
1467+ }
1468+
1469+ FailedMessageEvent
1470+ ~~~~~~~~~~~~
1471+
1472+ ``FailedMessageEvent `` it allows acting on the the initial message in case of a failure::
1473+
1474+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1475+ use Symfony\Component\Mailer\Event\FailedMessageEvent;
1476+
1477+ class MailerSubscriber implements EventSubscriberInterface
1478+ {
1479+ public static function getSubscribedEvents(): array
1480+ {
1481+ return [
1482+ FailedMessageEvent::class => 'onMessage',
1483+ ];
1484+ }
1485+
1486+ public function onMessage(FailedMessageEvent $event): void
1487+ {
1488+ // e.g you can debug sending an email with the getError() method
1489+ $event->getError();
1490+
1491+ // do something with the message
1492+ }
1493+ }
1494+
1495+ .. versionadded :: 6.2
1496+
1497+ ``SentMessageEvent `` and ``FailedMessageEvent `` was introduced in Symfony 6.2.
1498+
14401499Development & Debugging
14411500-----------------------
14421501
0 commit comments