Skip to content

Commit b804087

Browse files
committed
Merge pull request symfony#3464 from xabbuh/issue-3440
document the ability to configure more than one mailer at the same time
2 parents e710186 + 98b8ecc commit b804087

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

reference/configuration/swiftmailer.rst

+65
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ options, see `Full Default Configuration`_
1111
The ``swiftmailer`` key configures Symfony's integration with Swift Mailer,
1212
which is responsible for creating and delivering email messages.
1313

14+
The following section lists all options that are available to configure a
15+
mailer. It is also possible to configure several mailers (see `Using Multiple Mailers`_).
16+
1417
Configuration
1518
-------------
1619

@@ -220,3 +223,65 @@ Full Default Configuration
220223
threshold="99"
221224
/>
222225
</swiftmailer:config>
226+
227+
Using Multiple Mailers
228+
----------------------
229+
230+
You can configure multiple mailers by grouping them under the ``mailers``
231+
key (the default mailer is identified by the ``default_mailer`` option):
232+
233+
.. configuration-block::
234+
235+
.. code-block:: yaml
236+
237+
swiftmailer:
238+
default_mailer: second_mailer
239+
mailers:
240+
first_mailer:
241+
# ...
242+
second_mailer:
243+
# ...
244+
245+
.. code-block:: xml
246+
247+
<?xml version="1.0" encoding="UTF-8" ?>
248+
<container xmlns="http://symfony.com/schema/dic/services"
249+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
250+
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
251+
xsi:schemaLocation="http://symfony.com/schema/dic/services
252+
http://symfony.com/schema/dic/services/services-1.0.xsd
253+
http://symfony.com/schema/dic/swiftmailer
254+
http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd"
255+
>
256+
<swiftmailer:config default-mailer="second_mailer">
257+
<swiftmailer:mailer name="first_mailer"/>
258+
<swiftmailer:mailer name="second_mailer"/>
259+
</swiftmailer:config>
260+
</container>
261+
262+
.. code-block:: php
263+
264+
$container->loadFromExtension('swiftmailer', array(
265+
'default_mailer' => 'second_mailer',
266+
'mailers' => array(
267+
'first_mailer' => array(
268+
// ...
269+
),
270+
'second_mailer' => array(
271+
// ...
272+
),
273+
),
274+
));
275+
276+
Each mailer is registered as a service::
277+
278+
// ...
279+
280+
// returns the first mailer
281+
$container->get('swiftmailer.mailer.first_mailer');
282+
283+
// also returns the second mailer since it is the default mailer
284+
$container->get('swiftmailer.mailer');
285+
286+
// returns the second mailer
287+
$container->get('swiftmailer.mailer.second_mailer');

0 commit comments

Comments
 (0)