-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Mailer] Add docs about Mailer stamps #17390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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. | ||
Comment on lines
+1492
to
+1495
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This paragraph seems to contradict the "do something with the message" comment in the code example above. Is it saying "you can change the messenger message, but not the email" or is this a copy-paste error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can change the message if you want to, it will just be ignored. That's useful when you want to get errors early on (before sending things to the queue) like rendering the message to be sure there are no errors in templates. I have added a parenthesis with logging t make things a bit clearer about the primary use cases. |
||
|
||
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 | ||
~~~~~~~~~~~~~~~~ | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.