@@ -6,7 +6,7 @@ How to Work with Emails during Development
66
77When developing an application which sends email, you will often
88not want to actually send the email to the specified recipient during
9- development. If you are using theSwiftmailerBundle with Symfony, you
9+ development. If you are using thedefault Symfony mailer , you
1010can easily achieve this through configuration settings without having to
1111make any changes to your application's code at all. There are two main
1212choices when it comes to handling email during development: (a) disabling the
@@ -16,23 +16,21 @@ address (with optional exceptions).
1616Disabling Sending
1717-----------------
1818
19- You can disable sending email by setting the ``disable_delivery `` option
20- to ``true ``. This is the default in the ``test `` environment in the Standard
21- distribution. If you do this in the ``test `` specific config then email
22- will not be sent when you run tests, but will continue to be sent in the
23- ``prod `` and ``dev `` environments:
19+ You can disable sending email by setting the ``disable_delivery `` option to
20+ ``true ``, which is the default value used by Symfony in the ``test `` environment
21+ (email messages will continue to be sent in the other environments):
2422
2523..configuration-block ::
2624
2725 ..code-block ::yaml
2826
29- # app/ config/config_test.yml
27+ # config/packages/test/swiftmailer.yaml
3028swiftmailer :
3129disable_delivery :true
3230
3331 ..code-block ::xml
3432
35- <!-- app/ config/config_test .xml-->
33+ <!-- config/packages/test/swiftmailer .xml-->
3634 <?xml version =" 1.0" encoding =" UTF-8" ?>
3735 <container xmlns =" http://symfony.com/schema/dic/services"
3836xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -46,14 +44,11 @@ will not be sent when you run tests, but will continue to be sent in the
4644
4745 ..code-block ::php
4846
49- //app/ config/config_test .php
47+ // config/packages/test/swiftmailer .php
5048 $container->loadFromExtension('swiftmailer', array(
5149 'disable_delivery' => "true",
5250 ));
5351
54- If you'd also like to disable deliver in the ``dev `` environment, simply
55- add this same configuration to the ``config_dev.yml `` file.
56-
5752 .. _sending-to-a-specified-address :
5853
5954Sending to a Specified Address(es)
@@ -67,13 +62,13 @@ via the ``delivery_addresses`` option:
6762
6863 ..code-block ::yaml
6964
70- # app/ config/config_dev.yml
65+ # config/packages/dev/swiftmailer.yaml
7166swiftmailer :
7267delivery_addresses :['dev@example.com']
7368
7469 ..code-block ::xml
7570
76- <!-- app/ config/config_dev .xml-->
71+ <!-- config/packages/dev/swiftmailer .xml-->
7772 <?xml version =" 1.0" encoding =" UTF-8" ?>
7873 <container xmlns =" http://symfony.com/schema/dic/services"
7974xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -90,16 +85,14 @@ via the ``delivery_addresses`` option:
9085
9186 ..code-block ::php
9287
93- //app/ config/config_dev .php
88+ // config/packages/dev/swiftmailer .php
9489 $container->loadFromExtension('swiftmailer', array(
9590 'delivery_addresses' => array("dev@example.com"),
9691 ));
9792
98- Now, suppose you're sending an email to ``recipient@example.com ``.
99-
100- ..code-block ::php
93+ Now, suppose you're sending an email to ``recipient@example.com `` in a controller::
10194
102- public functionindexAction ($name, \Swift_Mailer $mailer)
95+ public functionindex ($name, \Swift_Mailer $mailer)
10396 {
10497 $message = (new \Swift_Message('Hello Email'))
10598 ->setFrom('send@example.com')
@@ -143,7 +136,7 @@ by adding the ``delivery_whitelist`` option:
143136
144137 ..code-block ::yaml
145138
146- # app/ config/config_dev.yml
139+ # config/packages/dev/swiftmailer.yaml
147140swiftmailer :
148141delivery_addresses :['dev@example.com']
149142delivery_whitelist :
@@ -154,7 +147,7 @@ by adding the ``delivery_whitelist`` option:
154147
155148 ..code-block ::xml
156149
157- <!-- app/ config/config_dev .xml-->
150+ <!-- config/packages/dev/swiftmailer .xml-->
158151 <?xml version =" 1.0" encoding =" UTF-8" ?>
159152 <container xmlns =" http://symfony.com/schema/dic/services"
160153xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -175,7 +168,7 @@ by adding the ``delivery_whitelist`` option:
175168
176169 ..code-block ::php
177170
178- //app/ config/config_dev .php
171+ // config/packages/dev/swiftmailer .php
179172 $container->loadFromExtension('swiftmailer', array(
180173 'delivery_addresses' => array("dev@example.com"),
181174 'delivery_whitelist' => array(
@@ -207,20 +200,20 @@ the web debug toolbar will not display an email icon or a report on the next
207200page.
208201
209202Instead, you can set the ``intercept_redirects `` option to ``true `` in the
210- ``config_dev.yml ``file , which will cause the redirect to stop and allow
211- you to open the report with details of the sent emails.
203+ ``dev ``environment , which will cause the redirect to stop and allow you to open
204+ the report with details of the sent emails.
212205
213206..configuration-block ::
214207
215208 ..code-block ::yaml
216209
217- # app/ config/config_dev.yml
210+ # config/packages/dev/swiftmailer.yaml
218211web_profiler :
219212intercept_redirects :true
220213
221214 ..code-block ::xml
222215
223- <!-- app/ config/config_dev .xml-->
216+ <!-- config/packages/dev/swiftmailer .xml-->
224217 <?xml version =" 1.0" encoding =" UTF-8" ?>
225218 <container xmlns =" http://symfony.com/schema/dic/services"
226219xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -237,7 +230,7 @@ you to open the report with details of the sent emails.
237230
238231 ..code-block ::php
239232
240- //app/ config/config_dev .php
233+ // config/packages/dev/swiftmailer .php
241234 $container->loadFromExtension('web_profiler', array(
242235 'intercept_redirects' => 'true',
243236 ));