Skip to content

[Mailer] Complete mailer documentation #14565

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 21, 2020
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
Complete mailer integration
  • Loading branch information
l-vo committed Nov 19, 2020
commit 074db0d1024b99d44918ceca65b5a68c547982d0
49 changes: 49 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,58 @@ over SMTP by configuring the DSN in your ``.env`` file (the ``user``,
# .env
MAILER_DSN=smtp://user:pass@smtp.example.com:port

.. configuration-block::

.. code-block:: yaml

# config/packages/mailer.yaml
framework:
mailer:
dsn: '%env(MAILER_DSN)%'

.. code-block:: xml

<!-- config/packages/mailer.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:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:mailer dsn="%env(MAILER_DSN)%"/>
</framework:config>
</container>

.. code-block:: php

// config/packages/mailer.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('framework', [
'mailer' => [
'dsn' => '%env(MAILER_DSN)%',
]
]);
};

.. caution::

If you are migrating from Swiftmailer (and the Swiftmailer bundle), be
warned that the DSN format is different.

Using built-in transports
~~~~~~~~~~~~~~~~~~~~~~~~~

============ ==================================== ===========
DSN protocol Example Description
============ ==================================== ===========
smtp smtp://user:pass@smtp.example.com:25 Mailer uses an SMTP server to send emails
sendmail sendmail://default Mailer uses the local sendmail binary to send emails
============ ==================================== ===========


Using a 3rd Party Transport
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -822,6 +869,8 @@ and it will select the appropriate certificate depending on the ``To`` option::
$firstEncryptedEmail = $encrypter->encrypt($firstEmail);
$secondEncryptedEmail = $encrypter->encrypt($secondEmail);

.. _multiple-email-transports:

Multiple Email Transports
-------------------------

Expand Down
116 changes: 113 additions & 3 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Configuration
* `cafile`_
* `capath`_
* `ciphers`_
* `headers`_
* :ref:`headers <http-headers>`
* `http_version`_
* `local_cert`_
* `local_pk`_
Expand Down Expand Up @@ -126,7 +126,7 @@ Configuration
* `cafile`_
* `capath`_
* `ciphers`_
* `headers`_
* :ref:`headers <http-headers>`
* `http_version`_
* `local_cert`_
* `local_pk`_
Expand All @@ -151,6 +151,17 @@ Configuration

* :ref:`name <reference-lock-resources-name>`

* `mailer`_

* :ref:`dsn <mailer-dsn>`
* `transports`_
* `envelope`_

* `sender`_
* `recipients`_

* :ref:`headers <mailer-headers>`

* `php_errors`_

* `log`_
Expand All @@ -159,7 +170,7 @@ Configuration
* `profiler`_

* `collect`_
* `dsn`_
* :ref:`dsn <profiler-dsn>`
* :ref:`enabled <reference-profiler-enabled>`
* `only_exceptions`_
* `only_master_requests`_
Expand Down Expand Up @@ -867,6 +878,8 @@ ciphers
A list of the names of the ciphers allowed for the SSL/TLS connections. They
can be separated by colons, commas or spaces (e.g. ``'RC4-SHA:TLS13-AES-128-GCM-SHA256'``).

.. _http-headers:

headers
.......

Expand Down Expand Up @@ -1075,6 +1088,8 @@ only_master_requests
When this is set to ``true``, the profiler will only be enabled on the master
requests (and not on the subrequests).

.. _profiler-dsn:

dsn
...

Expand Down Expand Up @@ -2888,6 +2903,101 @@ Name of the lock you want to create.
decorates: lock.invoice.store
arguments: ['@lock.invoice.retry_till_save.store.inner', 100, 50]

mailer
~~~~~~

.. _mailer-dsn:

dsn
...

**type**: ``string``

The DSN used by the mailer. When several DSN may be used, use `transports` (see below) instead.

transports
..........

**type**: ``array``

A :ref:`list of DSN <multiple-email-transports>` that can be used by the mailer. A transport name is the key and the dsn is the value.

envelope
........

sender
""""""

**type**: ``string``

Sender used by the ``Mailer``. Keep in mind that this setting override a sender set in the code.

recipients
""""""""""

**type**: ``array``

Recipients used by the ``Mailer``. Keep in mind that this setting override recipients set in the code.

.. configuration-block::

.. code-block:: yaml

# config/packages/mailer.yaml
framework:
mailer:
dsn: 'smtp://localhost:25'
envelope:
recipients: ['admin@symfony.com', 'lead@symfony.com']

.. code-block:: xml

<!-- config/packages/mailer.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:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:mailer dsn="smtp://localhost:25">
<framework:envelope>
<framework:recipients>admin@symfony.com</framework:recipients>
<framework:recipients>lead@symfony.com</framework:recipients>
</framework:envelope>
</framework:mailer>
</framework:config>
</container>

.. code-block:: php

// config/packages/mailer.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('framework', [
'mailer' => [
'dsn' => 'smtp://localhost:25',
'envelope' => [
'recipients' => [
'admin@symfony.com',
'lead@symfony.com',
]
]
]
]);
};

.. _mailer-headers:

headers
.......

**type**: ``array``

Headers to add to emails. key (``name`` attribute in xml format)
is the header name and value the header value.

workflows
~~~~~~~~~

Expand Down