Skip to content

Updated the email/* articles #8667

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
Nov 17, 2017
Merged
Show file tree
Hide file tree
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
88 changes: 10 additions & 78 deletions email/cloud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,86 +18,18 @@ This article shows how easy it is to integrate
.. note::

You can use the same technique for other mail services, as most of the
time there is nothing more to it than configuring an SMTP endpoint for
Swift Mailer.

In the Symfony configuration, change the Swift Mailer settings ``transport``,
``host``, ``port`` and ``encryption`` according to the information provided in
the `SES console`_. Create your individual SMTP credentials in the SES console
and complete the configuration with the provided ``username`` and ``password``:

.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
swiftmailer:
transport: smtp
host: email-smtp.us-east-1.amazonaws.com
port: 587 # different ports are available, see SES console
encryption: tls # TLS encryption is required
username: AWS_SES_SMTP_USERNAME # to be created in the SES console
password: AWS_SES_SMTP_PASSWORD # to be created in the SES console

.. code-block:: xml

<!-- app/config/config.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
transport="smtp"
host="email-smtp.us-east-1.amazonaws.com"
port="587"
encryption="tls"
username="AWS_SES_SMTP_USERNAME"
password="AWS_SES_SMTP_PASSWORD"
/>
</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('swiftmailer', array(
'transport' => 'smtp',
'host' => 'email-smtp.us-east-1.amazonaws.com',
'port' => 587,
'encryption' => 'tls',
'username' => 'AWS_SES_SMTP_USERNAME',
'password' => 'AWS_SES_SMTP_PASSWORD',
));

The ``port`` and ``encryption`` keys are not present in the Symfony Standard
Edition configuration by default, but you can simply add them as needed.
time there is nothing more to it than configuring an SMTP endpoint.

And that's it, you're ready to start sending emails through the cloud!
Symfony's mailer uses the ``MAILER_URL`` environment variable to store the
SMTP connection parameters, including the security credentials. Get those
parameters from the `SES console`_ and update the value of ``MAILER_URL`` in
the ``.env`` file:

.. code-block:: bash

.. tip::

If you are using the Symfony Standard Edition, configure the parameters in
``parameters.yml`` and use them in your configuration files. This allows
for different Swift Mailer configurations for each installation of your
application. For instance, use Gmail during development and the cloud in
production.

.. code-block:: yaml

# app/config/parameters.yml
parameters:
# ...
mailer_transport: smtp
mailer_host: email-smtp.us-east-1.amazonaws.com
mailer_port: 587 # different ports are available, see SES console
mailer_encryption: tls # TLS encryption is required
mailer_user: AWS_SES_SMTP_USERNAME # to be created in the SES console
mailer_password: AWS_SES_SMTP_PASSWORD # to be created in the SES console
MAILER_URL=smtp://email-smtp.us-east-1.amazonaws.com:587?encryption=tls&username=YOUR_SES_USERNAME&password=YOUR_SES_PASSWORD

And that's it, you're ready to start sending emails through the cloud!

.. note::

Expand Down
47 changes: 20 additions & 27 deletions email/dev_environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ How to Work with Emails during Development

When developing an application which sends email, you will often
not want to actually send the email to the specified recipient during
development. If you are using the SwiftmailerBundle with Symfony, you
development. If you are using the default Symfony mailer, you
can easily achieve this through configuration settings without having to
make any changes to your application's code at all. There are two main
choices when it comes to handling email during development: (a) disabling the
Expand All @@ -16,23 +16,21 @@ address (with optional exceptions).
Disabling Sending
-----------------

You can disable sending email by setting the ``disable_delivery`` option
to ``true``. This is the default in the ``test`` environment in the Standard
distribution. If you do this in the ``test`` specific config then email
will not be sent when you run tests, but will continue to be sent in the
``prod`` and ``dev`` environments:
You can disable sending email by setting the ``disable_delivery`` option to
``true``, which is the default value used by Symfony in the ``test`` environment
(email messages will continue to be sent in the other environments):

.. configuration-block::

.. code-block:: yaml

# app/config/config_test.yml
# config/packages/test/swiftmailer.yaml
swiftmailer:
disable_delivery: true

.. code-block:: xml

<!-- app/config/config_test.xml -->
<!-- config/packages/test/swiftmailer.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"
Expand All @@ -46,14 +44,11 @@ will not be sent when you run tests, but will continue to be sent in the

.. code-block:: php

// app/config/config_test.php
// config/packages/test/swiftmailer.php
$container->loadFromExtension('swiftmailer', array(
'disable_delivery' => "true",
));

If you'd also like to disable deliver in the ``dev`` environment, simply
add this same configuration to the ``config_dev.yml`` file.

.. _sending-to-a-specified-address:

Sending to a Specified Address(es)
Expand All @@ -67,13 +62,13 @@ via the ``delivery_addresses`` option:

.. code-block:: yaml

# app/config/config_dev.yml
# config/packages/dev/swiftmailer.yaml
swiftmailer:
delivery_addresses: ['[email protected]']

.. code-block:: xml

<!-- app/config/config_dev.xml -->
<!-- config/packages/dev/swiftmailer.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"
Expand All @@ -90,16 +85,14 @@ via the ``delivery_addresses`` option:

.. code-block:: php

// app/config/config_dev.php
// config/packages/dev/swiftmailer.php
$container->loadFromExtension('swiftmailer', array(
'delivery_addresses' => array("[email protected]"),
));

Now, suppose you're sending an email to ``[email protected]``.

.. code-block:: php
Now, suppose you're sending an email to ``[email protected]`` in a controller::

public function indexAction($name, \Swift_Mailer $mailer)
public function index($name, \Swift_Mailer $mailer)
{
$message = (new \Swift_Message('Hello Email'))
->setFrom('[email protected]')
Expand Down Expand Up @@ -143,7 +136,7 @@ by adding the ``delivery_whitelist`` option:

.. code-block:: yaml

# app/config/config_dev.yml
# config/packages/dev/swiftmailer.yaml
swiftmailer:
delivery_addresses: ['[email protected]']
delivery_whitelist:
Expand All @@ -154,7 +147,7 @@ by adding the ``delivery_whitelist`` option:

.. code-block:: xml

<!-- app/config/config_dev.xml -->
<!-- config/packages/dev/swiftmailer.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"
Expand All @@ -175,7 +168,7 @@ by adding the ``delivery_whitelist`` option:

.. code-block:: php

// app/config/config_dev.php
// config/packages/dev/swiftmailer.php
$container->loadFromExtension('swiftmailer', array(
'delivery_addresses' => array("[email protected]"),
'delivery_whitelist' => array(
Expand Down Expand Up @@ -207,20 +200,20 @@ the web debug toolbar will not display an email icon or a report on the next
page.

Instead, you can set the ``intercept_redirects`` option to ``true`` in the
``config_dev.yml`` file, which will cause the redirect to stop and allow
you to open the report with details of the sent emails.
``dev`` environment, which will cause the redirect to stop and allow you to open
the report with details of the sent emails.

.. configuration-block::

.. code-block:: yaml

# app/config/config_dev.yml
# config/packages/dev/swiftmailer.yaml
web_profiler:
intercept_redirects: true

.. code-block:: xml

<!-- app/config/config_dev.xml -->
<!-- config/packages/dev/swiftmailer.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"
Expand All @@ -237,7 +230,7 @@ you to open the report with details of the sent emails.

.. code-block:: php

// app/config/config_dev.php
// config/packages/dev/swiftmailer.php
$container->loadFromExtension('web_profiler', array(
'intercept_redirects' => 'true',
));
Expand Down
97 changes: 5 additions & 92 deletions email/gmail.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,102 +5,15 @@ How to Use Gmail to Send Emails
===============================

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

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

.. configuration-block::
.. code-block:: bash

.. code-block:: yaml

# app/config/config_dev.yml
swiftmailer:
transport: gmail
username: your_gmail_username
password: your_gmail_password

.. code-block:: xml

<!-- app/config/config_dev.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
transport="gmail"
username="your_gmail_username"
password="your_gmail_password"
/>
</container>

.. code-block:: php

// app/config/config_dev.php
$container->loadFromExtension('swiftmailer', array(
'transport' => 'gmail',
'username' => 'your_gmail_username',
'password' => 'your_gmail_password',
));

.. tip::

It's more convenient to configure these options in the ``parameters.yml``
file:

.. code-block:: yaml

# app/config/parameters.yml
parameters:
# ...
mailer_user: your_gmail_username
mailer_password: your_gmail_password

.. configuration-block::

.. code-block:: yaml

# app/config/config_dev.yml
swiftmailer:
transport: gmail
username: '%mailer_user%'
password: '%mailer_password%'

.. code-block:: xml

<!-- app/config/config_dev.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
transport="gmail"
username="%mailer_user%"
password="%mailer_password%"
/>
</container>

.. code-block:: php

// app/config/config_dev.php
$container->loadFromExtension('swiftmailer', array(
'transport' => 'gmail',
'username' => '%mailer_user%',
'password' => '%mailer_password%',
));
MAILER_URL=gmail://YOUR_GMAIL_USERNAME:YOUR_GMAIL_PASSWORD@localhost

Redefining the Default Configuration Parameters
-----------------------------------------------
Expand Down
Loading