Skip to content

Commit aeedbd2

Browse files
hiddewiejaviereguiluz
authored andcommitted
[Mailer] Add support for multiple mailers
1 parent 752c1f2 commit aeedbd2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

mailer.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,38 @@ you have a transport called ``async``, you can route the message there:
697697
Thanks to this, instead of being delivered immediately, messages will be sent to
698698
the transport to be handled later (see :ref:`messenger-worker`).
699699

700+
Mutliple email transports
701+
-------------------------
702+
703+
.. versionadded:: 4.4
704+
705+
The option to define multiple email transports was introduced in Symfony 4.4.
706+
707+
You may want to use more than one mailer transport for delivery of your messages.
708+
This can be configured by replacing the ``dsn`` configuration entry with a
709+
``transports`` entry, like:
710+
711+
.. code-block:: yaml
712+
713+
# config/packages/mailer.yaml
714+
framework:
715+
mailer:
716+
transports:
717+
main: '%env(MAILER_DSN)%'
718+
important: '%env(MAILER_DSN_IMPORTANT)%'
719+
720+
By default the first transport is used. The other tranports can be used by adding
721+
a text header ``X-Transport`` to an email:
722+
723+
.. code-block:: php
724+
725+
// Send using first "main" transport ...
726+
$mailer->send($email);
727+
728+
// ... or use the "important" one
729+
$email->getHeaders()->addTextHeader('X-Transport', 'important');
730+
$mailer->send($email);
731+
700732
Development & Debugging
701733
-----------------------
702734

0 commit comments

Comments
 (0)