File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff 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+
13591392Development & Debugging
13601393-----------------------
13611394
You can’t perform that action at this time.
0 commit comments