Skip to content

Commit 9e11eea

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: Add event subscriber example to mailer documentation amqp no autocreate queues, see symfony#16689
2 parents 311016f + f4202ee commit 9e11eea

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

mailer.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ and headers.
605605
.. versionadded:: 5.2
606606

607607
The ``headers`` option was introduced in Symfony 5.2.
608-
608+
609609
.. caution::
610610

611611
Some third-party providers don't support the usage of keywords like ``from``
@@ -1356,6 +1356,39 @@ The following transports only support tags:
13561356

13571357
* OhMySMTP
13581358

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

0 commit comments

Comments
 (0)