Skip to content

Commit 9a4075d

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: Add event subscriber example to mailer documentation amqp no autocreate queues, see #16689
2 parents fcd3d4b + 53cf3c2 commit 9a4075d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

mailer.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,39 @@ Here's an example of making one available to download::
13551355
As it's possible for :class:`Symfony\\Component\\Mime\\DraftEmail`'s to be created
13561356
without a To/From they cannot be sent with the mailer.
13571357

1358+
Mailer Events
1359+
-------------
1360+
1361+
MessageEvent
1362+
~~~~~~~~~~~~
1363+
1364+
``MessageEvent`` allows to change the Message and the Envelope before the email
1365+
is sent::
1366+
1367+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1368+
use Symfony\Component\Mailer\Event\MessageEvent;
1369+
use Symfony\Component\Mime\Email;
1370+
1371+
class MailerSubscriber implements EventSubscriberInterface
1372+
{
1373+
public static function getSubscribedEvents()
1374+
{
1375+
return [
1376+
MessageEvent::class => 'onMessage',
1377+
];
1378+
}
1379+
1380+
public function onMessage(MessageEvent $event): void
1381+
{
1382+
$message = $event->getMessage();
1383+
if (!$message instanceof Email) {
1384+
return;
1385+
}
1386+
1387+
// do something with the message
1388+
}
1389+
}
1390+
13581391
Development & Debugging
13591392
-----------------------
13601393

0 commit comments

Comments
 (0)