Skip to content

Commit a8ed262

Browse files
committed
Complete documentation about mailer integration
1 parent 52c2ca0 commit a8ed262

File tree

2 files changed

+174
-4
lines changed

2 files changed

+174
-4
lines changed

mailer.rst

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,64 @@ over SMTP by configuring the DNS in your ``.env`` file (the ``user``,
2727
# .env
2828
MAILER_DSN=smtp://user:pass@smtp.example.com:port
2929
30+
.. configuration-block::
31+
32+
.. code-block:: yaml
33+
34+
# config/packages/mailer.yaml
35+
framework:
36+
mailer:
37+
dsn: '%env(MAILER_DSN)%'
38+
39+
.. code-block:: xml
40+
41+
<!-- config/packages/mailer.xml -->
42+
<?xml version="1.0" encoding="UTF-8" ?>
43+
<container xmlns="http://symfony.com/schema/dic/services"
44+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45+
xmlns:framework="http://symfony.com/schema/dic/symfony"
46+
xsi:schemaLocation="http://symfony.com/schema/dic/services
47+
https://symfony.com/schema/dic/services/services-1.0.xsd
48+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
49+
50+
<framework:config>
51+
<framework:mailer dsn="%env(MAILER_DSN)%"/>
52+
</framework:config>
53+
</container>
54+
55+
.. code-block:: php
56+
57+
// config/packages/mailer.php
58+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
59+
60+
return static function (ContainerConfigurator $containerConfigurator): void {
61+
$containerConfigurator->extension('framework', [
62+
'mailer' => [
63+
'dsn' => '%env(MAILER_DSN)%',
64+
]
65+
]);
66+
};
67+
3068
.. caution::
3169

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

73+
Using built-in transports
74+
~~~~~~~~~~~~~~~~~~~~~~~~~
75+
76+
============ ==================================== ===========
77+
DSN protocol Example Description
78+
============ ==================================== ===========
79+
smtp smtp://user:pass@smtp.example.com:25 Mailer use an SMTP server to send emails
80+
sendmail sendmail://default Mailer use the local sendmail binary (`/usr/sbin/sendmail` with `-bs` options) to send emails
81+
native native://default Mailer use the sendmail binary and options configured in the `sendmail_path` setting of `php.ini`. On Windows hosts, Mailer fallbacks to `smtp` and `smtp_port` `php.ini` settings when `sendmail_path` is not configured.
82+
============ ==================================== ===========
83+
3584
Using a 3rd Party Transport
3685
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3786

38-
Instead of using your own SMTP server, you can send emails via a 3rd party
87+
Instead of using your own SMTP server or sendmail binary, you can send emails via a 3rd party
3988
provider. Mailer supports several - install whichever you want:
4089

4190
================== =============================================
@@ -897,6 +946,8 @@ and it will select the appropriate certificate depending on the ``To`` option::
897946
$firstEncryptedEmail = $encrypter->encrypt($firstEmail);
898947
$secondEncryptedEmail = $encrypter->encrypt($secondEmail);
899948

949+
.. _multiple-email-transports:
950+
900951
Multiple Email Transports
901952
-------------------------
902953

reference/configuration/framework.rst

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Configuration
9898
* `cafile`_
9999
* `capath`_
100100
* `ciphers`_
101-
* `headers`_
101+
* :ref:`headers <http-headers>`
102102
* `http_version`_
103103
* `local_cert`_
104104
* `local_pk`_
@@ -126,7 +126,7 @@ Configuration
126126
* `cafile`_
127127
* `capath`_
128128
* `ciphers`_
129-
* `headers`_
129+
* :ref:`headers <http-headers>`
130130
* `http_version`_
131131
* `local_cert`_
132132
* `local_pk`_
@@ -151,6 +151,18 @@ Configuration
151151

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

154+
* `mailer`_
155+
156+
* :ref:`dsn <mailer-dsn>`
157+
* `transports`_
158+
* `message_bus`_
159+
* `envelope`_
160+
161+
* `sender`_
162+
* `recipients`_
163+
164+
* :ref:`headers <mailer-headers>`
165+
154166
* `php_errors`_
155167

156168
* `log`_
@@ -159,7 +171,7 @@ Configuration
159171
* `profiler`_
160172

161173
* `collect`_
162-
* `dsn`_
174+
* :ref:`dsn <profiler-dsn>`
163175
* :ref:`enabled <reference-profiler-enabled>`
164176
* `only_exceptions`_
165177
* `only_master_requests`_
@@ -835,6 +847,8 @@ ciphers
835847
A list of the names of the ciphers allowed for the SSL/TLS connections. They
836848
can be separated by colons, commas or spaces (e.g. ``'RC4-SHA:TLS13-AES-128-GCM-SHA256'``).
837849

850+
.. _http-headers:
851+
838852
headers
839853
.......
840854

@@ -1039,6 +1053,8 @@ only_master_requests
10391053
When this is set to ``true``, the profiler will only be enabled on the master
10401054
requests (and not on the subrequests).
10411055

1056+
.. _profiler-dsn:
1057+
10421058
dsn
10431059
...
10441060

@@ -2819,6 +2835,109 @@ Name of the lock you want to create.
28192835
decorates: lock.invoice.store
28202836
arguments: ['@.inner', 100, 50]
28212837
2838+
mailer
2839+
~~~~~~
2840+
2841+
.. _mailer-dsn:
2842+
2843+
dsn
2844+
...
2845+
2846+
**type**: ``string``
2847+
2848+
The DSN used by the mailer. When several DSN may be used, use `transports` (see below) instead.
2849+
2850+
transports
2851+
..........
2852+
2853+
**type**: ``array``
2854+
2855+
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.
2856+
2857+
message_bus
2858+
...........
2859+
2860+
**type**: ``string`` | ``false``
2861+
2862+
Service identifier of the bus to use (when the messenger component is installed, for instance `messenger.default_bus`)
2863+
2864+
envelope
2865+
........
2866+
2867+
sender
2868+
""""""
2869+
2870+
**type**: ``string``
2871+
2872+
Sender used by the `Mailer`. Keep in mind that this setting override a sender set in the code.
2873+
2874+
recipients
2875+
""""""""""
2876+
2877+
**type**: ``array``
2878+
2879+
Recipients used by the `Mailer`. Keep in mind that this setting override recipients set in the code.
2880+
2881+
.. configuration-block::
2882+
2883+
.. code-block:: yaml
2884+
2885+
# config/packages/mailer.yaml
2886+
framework:
2887+
mailer:
2888+
dsn: 'smtp://localhost:25'
2889+
envelope:
2890+
recipients: ['admin@symfony.com', 'lead@symfony.com']
2891+
2892+
.. code-block:: xml
2893+
2894+
<!-- config/packages/mailer.xml -->
2895+
<?xml version="1.0" encoding="UTF-8" ?>
2896+
<container xmlns="http://symfony.com/schema/dic/services"
2897+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2898+
xmlns:framework="http://symfony.com/schema/dic/symfony"
2899+
xsi:schemaLocation="http://symfony.com/schema/dic/services
2900+
https://symfony.com/schema/dic/services/services-1.0.xsd
2901+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
2902+
2903+
<framework:config>
2904+
<framework:mailer dsn="smtp://localhost:25">
2905+
<framework:envelope>
2906+
<framework:recipients>admin@symfony.com</framework:recipients>
2907+
<framework:recipients>lead@symfony.com</framework:recipients>
2908+
</framework:envelope>
2909+
</framework:mailer>
2910+
</framework:config>
2911+
</container>
2912+
2913+
.. code-block:: php
2914+
2915+
// config/packages/mailer.php
2916+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
2917+
2918+
return static function (ContainerConfigurator $containerConfigurator): void {
2919+
$containerConfigurator->extension('framework', [
2920+
'mailer' => [
2921+
'dsn' => 'smtp://localhost:25',
2922+
'envelope' => [
2923+
'recipients' => [
2924+
'admin@symfony.com',
2925+
'lead@symfony.com'
2926+
]
2927+
]
2928+
]
2929+
]);
2930+
};
2931+
2932+
.. _mailer-headers:
2933+
2934+
headers
2935+
.......
2936+
2937+
**type**: ``array``
2938+
2939+
Headers to add to emails. key (`name` attribute in xml format) is the header name and value the header value.
2940+
28222941
workflows
28232942
~~~~~~~~~
28242943

0 commit comments

Comments
 (0)