Skip to content

Commit

Permalink
Add docs about Mailer stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 24, 2022
1 parent 0b60280 commit 7dbe950
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,8 @@ MessageEvent

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

``MessageEvent`` allows to change the Message and the Envelope before the email
is sent::
``MessageEvent`` allows to change the Mailer message and the envelope before
the email is sent::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\MessageEvent;
Expand Down Expand Up @@ -1459,6 +1459,48 @@ and their priorities:
$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\MessageEvent"
QueuingMessageEvent
~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\QueuingMessageEvent`

.. versionadded:: 6.2

The ``QueuingMessageEvent`` class was introduced in Symfony 6.2.

``QueuingMessageEvent`` allows to add some logic before the email is sent to
the Messenger bus (this event is not dispatched when no bus is configured); it
extends ``MessageEvent`` to allow adding Messenger stamps to the Messenger
message sent to the bus::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\QueuingMessageEvent;
use Symfony\Component\Mime\Email;

public function onMessage(QueuingMessageEvent $event): void
{
$message = $event->getMessage();
if (!$message instanceof Email) {
return;
}
// do something with the message (logging, ...)

// and/or add some Messenger stamps
$event->addStamp(new SomeMessengerStamp());
}

This event lets listeners do something before a message is sent to the queue
(like adding stamps or logging) but any changes to the message or the envelope
are discarded. To change the message or the envelope, listen to
``MessageEvent`` instead.

Execute this command to find out which listeners are registered for this event
and their priorities:

.. code-block:: terminal
$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\QueuingMessageEvent"
SentMessageEvent
~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 7dbe950

Please sign in to comment.