Skip to content

[Mailer] Add support for multiple mailers #12422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,38 @@ you have a transport called ``async``, you can route the message there:
Thanks to this, instead of being delivered immediately, messages will be sent to
the transport to be handled later (see :ref:`messenger-worker`).

Mutliple email transports
-------------------------

.. versionadded:: 4.4

The option to define multiple email transports was introduced in Symfony 4.4.

You may want to use more than one mailer transport for delivery of your messages.
This can be configured by replacing the ``dsn`` configuration entry with a
``transports`` entry, like:

.. code-block:: yaml

# config/packages/mailer.yaml
framework:
mailer:
transports:
main: '%env(MAILER_DSN)%'
important: '%env(MAILER_DSN_IMPORTANT)%'

By default the first transport is used. The other tranports can be used by adding
a text header ``X-Transport`` to an email:

.. code-block:: php

// Send using first "main" transport ...
$mailer->send($email);

// ... or use the "important" one
$email->getHeaders()->addTextHeader('X-Transport', 'important');
$mailer->send($email);

Development & Debugging
-----------------------

Expand Down