Skip to content

Commit acbd9b2

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Add event subscriber example to mailer documentation amqp no autocreate queues, see symfony#16689
2 parents 608aebc + 9a4075d commit acbd9b2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

mailer.rst

+33
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,39 @@ Here's an example of making one available to download::
14041404
As it's possible for :class:`Symfony\\Component\\Mime\\DraftEmail`'s to be created
14051405
without a To/From they cannot be sent with the mailer.
14061406

1407+
Mailer Events
1408+
-------------
1409+
1410+
MessageEvent
1411+
~~~~~~~~~~~~
1412+
1413+
``MessageEvent`` allows to change the Message and the Envelope before the email
1414+
is sent::
1415+
1416+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1417+
use Symfony\Component\Mailer\Event\MessageEvent;
1418+
use Symfony\Component\Mime\Email;
1419+
1420+
class MailerSubscriber implements EventSubscriberInterface
1421+
{
1422+
public static function getSubscribedEvents()
1423+
{
1424+
return [
1425+
MessageEvent::class => 'onMessage',
1426+
];
1427+
}
1428+
1429+
public function onMessage(MessageEvent $event): void
1430+
{
1431+
$message = $event->getMessage();
1432+
if (!$message instanceof Email) {
1433+
return;
1434+
}
1435+
1436+
// do something with the message
1437+
}
1438+
}
1439+
14071440
Development & Debugging
14081441
-----------------------
14091442

0 commit comments

Comments
 (0)