@@ -1419,7 +1419,7 @@ is sent::
1419
1419
1420
1420
class MailerSubscriber implements EventSubscriberInterface
1421
1421
{
1422
- public static function getSubscribedEvents()
1422
+ public static function getSubscribedEvents(): array
1423
1423
{
1424
1424
return [
1425
1425
MessageEvent::class => 'onMessage',
@@ -1437,6 +1437,65 @@ is sent::
1437
1437
}
1438
1438
}
1439
1439
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
+
1440
1499
Development & Debugging
1441
1500
-----------------------
1442
1501
0 commit comments