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