Skip to content

Commit 53cf3c2

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

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
@@ -1274,6 +1274,39 @@ The following transports only support tags:
12741274

12751275
* OhMySMTP
12761276

1277+
Mailer Events
1278+
-------------
1279+
1280+
MessageEvent
1281+
~~~~~~~~~~~~
1282+
1283+
``MessageEvent`` allows to change the Message and the Envelope before the email
1284+
is sent::
1285+
1286+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1287+
use Symfony\Component\Mailer\Event\MessageEvent;
1288+
use Symfony\Component\Mime\Email;
1289+
1290+
class MailerSubscriber implements EventSubscriberInterface
1291+
{
1292+
public static function getSubscribedEvents()
1293+
{
1294+
return [
1295+
MessageEvent::class => 'onMessage',
1296+
];
1297+
}
1298+
1299+
public function onMessage(MessageEvent $event): void
1300+
{
1301+
$message = $event->getMessage();
1302+
if (!$message instanceof Email) {
1303+
return;
1304+
}
1305+
1306+
// do something with the message
1307+
}
1308+
}
1309+
12771310
Development & Debugging
12781311
-----------------------
12791312

0 commit comments

Comments
 (0)