Skip to content

document the ability to configure more than one mailer at the same time #3464

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
Feb 1, 2014
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
65 changes: 65 additions & 0 deletions reference/configuration/swiftmailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ options, see `Full Default Configuration`_
The ``swiftmailer`` key configures Symfony's integration with Swift Mailer,
which is responsible for creating and delivering email messages.

The following section lists all options that are available to configure a
mailer. It is also possible to configure several mailers (see `Using Multiple Mailers`_).

Configuration
-------------

Expand Down Expand Up @@ -220,3 +223,65 @@ Full Default Configuration
threshold="99"
/>
</swiftmailer:config>

Using Multiple Mailers
----------------------

You can configure multiple mailers by grouping them under the ``mailers``
key (the default mailer is identified by the ``default_mailer`` option):

.. configuration-block::

.. code-block:: yaml

swiftmailer:
default_mailer: second_mailer
mailers:
first_mailer:
# ...
second_mailer:
# ...

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/swiftmailer
http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd"
>
<swiftmailer:config default-mailer="second_mailer">
<swiftmailer:mailer name="first_mailer"/>
<swiftmailer:mailer name="second_mailer"/>
</swiftmailer:config>
</container>

.. code-block:: php

$container->loadFromExtension('swiftmailer', array(
'default_mailer' => 'second_mailer',
'mailers' => array(
'first_mailer' => array(
// ...
),
'second_mailer' => array(
// ...
),
),
));

Each mailer is registered as a service::

// ...

// returns the first mailer
$container->get('swiftmailer.mailer.first_mailer');

// also returns the second mailer since it is the default mailer
$container->get('swiftmailer.mailer');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns the secondary mailer (following the cinguration above))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bicpi! Great catch!


// returns the second mailer
$container->get('swiftmailer.mailer.second_mailer');