File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1355,6 +1355,39 @@ Here's an example of making one available to download::
1355
1355
As it's possible for :class: `Symfony\\ Component\\ Mime\\ DraftEmail `'s to be created
1356
1356
without a To/From they cannot be sent with the mailer.
1357
1357
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
+
1358
1391
Development & Debugging
1359
1392
-----------------------
1360
1393
You can’t perform that action at this time.
0 commit comments