Skip to content

Commit bcdeeac

Browse files
committed
Updated the email/* articles
1 parent 845f424 commit bcdeeac

File tree

5 files changed

+55
-217
lines changed

5 files changed

+55
-217
lines changed

email/cloud.rst

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,86 +18,18 @@ This article shows how easy it is to integrate
1818
.. note::
1919

2020
You can use the same technique for other mail services, as most of the
21-
time there is nothing more to it than configuring an SMTP endpoint for
22-
Swift Mailer.
23-
24-
In the Symfony configuration, change the Swift Mailer settings ``transport``,
25-
``host``, ``port`` and ``encryption`` according to the information provided in
26-
the `SES console`_. Create your individual SMTP credentials in the SES console
27-
and complete the configuration with the provided ``username`` and ``password``:
28-
29-
.. configuration-block::
30-
31-
.. code-block:: yaml
32-
33-
# app/config/config.yml
34-
swiftmailer:
35-
transport: smtp
36-
host: email-smtp.us-east-1.amazonaws.com
37-
port: 587 # different ports are available, see SES console
38-
encryption: tls # TLS encryption is required
39-
username: AWS_SES_SMTP_USERNAME # to be created in the SES console
40-
password: AWS_SES_SMTP_PASSWORD # to be created in the SES console
41-
42-
.. code-block:: xml
43-
44-
<!-- app/config/config.xml -->
45-
<?xml version="1.0" encoding="UTF-8" ?>
46-
<container xmlns="http://symfony.com/schema/dic/services"
47-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48-
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
49-
xsi:schemaLocation="http://symfony.com/schema/dic/services
50-
http://symfony.com/schema/dic/services/services-1.0.xsd
51-
http://symfony.com/schema/dic/swiftmailer
52-
http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">
53-
54-
<!-- ... -->
55-
<swiftmailer:config
56-
transport="smtp"
57-
host="email-smtp.us-east-1.amazonaws.com"
58-
port="587"
59-
encryption="tls"
60-
username="AWS_SES_SMTP_USERNAME"
61-
password="AWS_SES_SMTP_PASSWORD"
62-
/>
63-
</container>
64-
65-
.. code-block:: php
66-
67-
// app/config/config.php
68-
$container->loadFromExtension('swiftmailer', array(
69-
'transport' => 'smtp',
70-
'host' => 'email-smtp.us-east-1.amazonaws.com',
71-
'port' => 587,
72-
'encryption' => 'tls',
73-
'username' => 'AWS_SES_SMTP_USERNAME',
74-
'password' => 'AWS_SES_SMTP_PASSWORD',
75-
));
76-
77-
The ``port`` and ``encryption`` keys are not present in the Symfony Standard
78-
Edition configuration by default, but you can simply add them as needed.
21+
time there is nothing more to it than configuring an SMTP endpoint.
7922

80-
And that's it, you're ready to start sending emails through the cloud!
23+
Symfony's mailer uses the ``MAILER_URL`` environment variable to store the
24+
SMTP connection parameters, including the security credentials. Get those
25+
parameters from the `SES console`_ and update the value of ``MAILER_URL`` in
26+
the ``.env`` file:
27+
28+
.. code-block:: bash
8129
82-
.. tip::
83-
84-
If you are using the Symfony Standard Edition, configure the parameters in
85-
``parameters.yml`` and use them in your configuration files. This allows
86-
for different Swift Mailer configurations for each installation of your
87-
application. For instance, use Gmail during development and the cloud in
88-
production.
89-
90-
.. code-block:: yaml
91-
92-
# app/config/parameters.yml
93-
parameters:
94-
# ...
95-
mailer_transport: smtp
96-
mailer_host: email-smtp.us-east-1.amazonaws.com
97-
mailer_port: 587 # different ports are available, see SES console
98-
mailer_encryption: tls # TLS encryption is required
99-
mailer_user: AWS_SES_SMTP_USERNAME # to be created in the SES console
100-
mailer_password: AWS_SES_SMTP_PASSWORD # to be created in the SES console
30+
MAILER_URL=smtp://email-smtp.us-east-1.amazonaws.com:587?encryption=tls&username=YOUR_SES_USERNAME&password=YOUR_SES_PASSWORD
31+
32+
And that's it, you're ready to start sending emails through the cloud!
10133

10234
.. note::
10335

email/dev_environment.rst

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ How to Work with Emails during Development
66

77
When developing an application which sends email, you will often
88
not want to actually send the email to the specified recipient during
9-
development. If you are using the SwiftmailerBundle with Symfony, you
9+
development. If you are using the default Symfony mailer, you
1010
can easily achieve this through configuration settings without having to
1111
make any changes to your application's code at all. There are two main
1212
choices when it comes to handling email during development: (a) disabling the
@@ -16,23 +16,21 @@ address (with optional exceptions).
1616
Disabling 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
3028
swiftmailer:
3129
disable_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"
3836
xmlns: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

5954
Sending 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
7166
swiftmailer:
7267
delivery_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"
7974
xmlns: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 function indexAction($name, \Swift_Mailer $mailer)
95+
public function index($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
147140
swiftmailer:
148141
delivery_addresses: ['dev@example.com']
149142
delivery_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"
160153
xmlns: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
207200
page.
208201

209202
Instead, 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
218211
web_profiler:
219212
intercept_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"
226219
xmlns: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
));

email/gmail.rst

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,102 +5,15 @@ How to Use Gmail to Send Emails
55
===============================
66

77
During development, instead of using a regular SMTP server to send emails, you
8-
might find using Gmail easier and more practical. The SwiftmailerBundle makes
8+
might find using Gmail easier and more practical. The Symfony mailer makes
99
it really easy.
1010

11-
In the development configuration file, change the ``transport`` setting to
12-
``gmail`` and set the ``username`` and ``password`` to the Google credentials:
11+
In the ``.env`` file used in your development machine, change the ``MAILER_URL``
12+
environment variable to this:
1313

14-
.. configuration-block::
14+
.. code-block:: bash
1515
16-
.. code-block:: yaml
17-
18-
# app/config/config_dev.yml
19-
swiftmailer:
20-
transport: gmail
21-
username: your_gmail_username
22-
password: your_gmail_password
23-
24-
.. code-block:: xml
25-
26-
<!-- app/config/config_dev.xml -->
27-
<?xml version="1.0" encoding="UTF-8" ?>
28-
<container xmlns="http://symfony.com/schema/dic/services"
29-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30-
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
31-
xsi:schemaLocation="http://symfony.com/schema/dic/services
32-
http://symfony.com/schema/dic/services/services-1.0.xsd
33-
http://symfony.com/schema/dic/swiftmailer
34-
http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">
35-
36-
<!-- ... -->
37-
<swiftmailer:config
38-
transport="gmail"
39-
username="your_gmail_username"
40-
password="your_gmail_password"
41-
/>
42-
</container>
43-
44-
.. code-block:: php
45-
46-
// app/config/config_dev.php
47-
$container->loadFromExtension('swiftmailer', array(
48-
'transport' => 'gmail',
49-
'username' => 'your_gmail_username',
50-
'password' => 'your_gmail_password',
51-
));
52-
53-
.. tip::
54-
55-
It's more convenient to configure these options in the ``parameters.yml``
56-
file:
57-
58-
.. code-block:: yaml
59-
60-
# app/config/parameters.yml
61-
parameters:
62-
# ...
63-
mailer_user: your_gmail_username
64-
mailer_password: your_gmail_password
65-
66-
.. configuration-block::
67-
68-
.. code-block:: yaml
69-
70-
# app/config/config_dev.yml
71-
swiftmailer:
72-
transport: gmail
73-
username: '%mailer_user%'
74-
password: '%mailer_password%'
75-
76-
.. code-block:: xml
77-
78-
<!-- app/config/config_dev.xml -->
79-
<?xml version="1.0" encoding="UTF-8" ?>
80-
<container xmlns="http://symfony.com/schema/dic/services"
81-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
82-
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
83-
xsi:schemaLocation="http://symfony.com/schema/dic/services
84-
http://symfony.com/schema/dic/services/services-1.0.xsd
85-
http://symfony.com/schema/dic/swiftmailer
86-
http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">
87-
88-
<!-- ... -->
89-
<swiftmailer:config
90-
transport="gmail"
91-
username="%mailer_user%"
92-
password="%mailer_password%"
93-
/>
94-
</container>
95-
96-
.. code-block:: php
97-
98-
// app/config/config_dev.php
99-
$container->loadFromExtension('swiftmailer', array(
100-
'transport' => 'gmail',
101-
'username' => '%mailer_user%',
102-
'password' => '%mailer_password%',
103-
));
16+
MAILER_URL=gmail://YOUR_GMAIL_USERNAME:YOUR_GMAIL_PASSWORD@localhost
10417
10518
Redefining the Default Configuration Parameters
10619
-----------------------------------------------

0 commit comments

Comments
 (0)