Skip to content

Commit 9a2b1ce

Browse files
committed
Add docs about Mailer stamps
1 parent 0b60280 commit 9a2b1ce

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

mailer.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,8 @@ MessageEvent
14291429

14301430
**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\MessageEvent`
14311431

1432-
``MessageEvent`` allows to change the Message and the Envelope before the email
1433-
is sent::
1432+
``MessageEvent`` allows to change the Mailer message and the envelope before
1433+
the email is sent::
14341434

14351435
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14361436
use Symfony\Component\Mailer\Event\MessageEvent;
@@ -1459,6 +1459,44 @@ and their priorities:
14591459
14601460
$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\MessageEvent"
14611461
1462+
QueuingMessageEvent
1463+
~~~~~~~~~~~~~~~~~~~
1464+
1465+
**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\QueuingMessageEvent`
1466+
1467+
``QueuingMessageEvent`` allows to add some logic before the email is sent to
1468+
the Messenger bus (this event is not dispatched when no bus is configured); it
1469+
extends ``MessageEvent`` to allow adding Messenger stamps to the Messenger
1470+
message sent to the bus::
1471+
1472+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1473+
use Symfony\Component\Mailer\Event\QueuingMessageEvent;
1474+
use Symfony\Component\Mime\Email;
1475+
1476+
public function onMessage(QueuingMessageEvent $event): void
1477+
{
1478+
$message = $event->getMessage();
1479+
if (!$message instanceof Email) {
1480+
return;
1481+
}
1482+
// do something with the message
1483+
1484+
// and/or add some Messenger stamps
1485+
$event->addStamp(new SomeMessengerStamp());
1486+
}
1487+
1488+
This event lets listeners do something before a message is sent to the queue
1489+
(like adding stamps or logging) but any changes to the message or the envelope
1490+
are discarded. To change the message or the envelope, listen to
1491+
``MessageEvent`` instead.
1492+
1493+
Execute this command to find out which listeners are registered for this event
1494+
and their priorities:
1495+
1496+
.. code-block:: terminal
1497+
1498+
$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\QueuingMessageEvent"
1499+
14621500
SentMessageEvent
14631501
~~~~~~~~~~~~~~~~
14641502

0 commit comments

Comments
 (0)