Skip to content

Commit febfdbb

Browse files
committed
Complete mailer integration
1 parent f5e0f47 commit febfdbb

File tree

2 files changed

+155
-3
lines changed

2 files changed

+155
-3
lines changed

mailer.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,55 @@ over SMTP by configuring the DSN in your ``.env`` file (the ``user``,
2929
# .env
3030
MAILER_DSN=smtp://user:pass@smtp.example.com:port
3131
32+
.. configuration-block::
33+
34+
.. code-block:: yaml
35+
# config/packages/mailer.yaml
36+
framework:
37+
mailer:
38+
dsn: '%env(MAILER_DSN)%'
39+
40+
.. code-block:: xml
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+
<framework:config>
50+
<framework:mailer dsn="%env(MAILER_DSN)%"/>
51+
</framework:config>
52+
</container>
53+
54+
.. code-block:: php
55+
// config/packages/mailer.php
56+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
57+
return static function (ContainerConfigurator $containerConfigurator): void {
58+
$containerConfigurator->extension('framework', [
59+
'mailer' => [
60+
'dsn' => '%env(MAILER_DSN)%',
61+
]
62+
]);
63+
};
64+
3265
.. caution::
3366

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

70+
Using built-in transports
71+
~~~~~~~~~~~~~~~~~~~~~~~~~
72+
73+
============ ==================================== ===========
74+
DSN protocol Example Description
75+
============ ==================================== ===========
76+
smtp smtp://user:pass@smtp.example.com:25 Mailer uses an SMTP server to send emails
77+
sendmail sendmail://default Mailer uses the local sendmail binary to send emails
78+
============ ==================================== ===========
79+
80+
3781
Using a 3rd Party Transport
3882
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3983

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

869+
.. _multiple-email-transports:
870+
825871
Multiple Email Transports
826872
-------------------------
827873

reference/configuration/framework.rst

Lines changed: 109 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,17 @@ Configuration
151151

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

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

156167
* `log`_
@@ -159,7 +170,7 @@ Configuration
159170
* `profiler`_
160171

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

881+
.. _http-headers:
882+
870883
headers
871884
.......
872885

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

1091+
.. _profiler-dsn:
1092+
10781093
dsn
10791094
...
10801095

@@ -2888,6 +2903,97 @@ Name of the lock you want to create.
28882903
decorates: lock.invoice.store
28892904
arguments: ['@lock.invoice.retry_till_save.store.inner', 100, 50]
28902905
2906+
mailer
2907+
~~~~~~
2908+
2909+
.. _mailer-dsn:
2910+
2911+
dsn
2912+
...
2913+
2914+
**type**: ``string``
2915+
2916+
The DSN used by the mailer. When several DSN may be used, use `transports` (see below) instead.
2917+
2918+
transports
2919+
..........
2920+
2921+
**type**: ``array``
2922+
2923+
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.
2924+
2925+
envelope
2926+
........
2927+
2928+
sender
2929+
""""""
2930+
2931+
**type**: ``string``
2932+
2933+
Sender used by the `Mailer`. Keep in mind that this setting override a sender set in the code.
2934+
2935+
recipients
2936+
""""""""""
2937+
2938+
**type**: ``array``
2939+
2940+
Recipients used by the `Mailer`. Keep in mind that this setting override recipients set in the code.
2941+
2942+
.. configuration-block::
2943+
2944+
.. code-block:: yaml
2945+
# config/packages/mailer.yaml
2946+
framework:
2947+
mailer:
2948+
dsn: 'smtp://localhost:25'
2949+
envelope:
2950+
recipients: ['admin@symfony.com', 'lead@symfony.com']
2951+
2952+
.. code-block:: xml
2953+
<!-- config/packages/mailer.xml -->
2954+
<?xml version="1.0" encoding="UTF-8" ?>
2955+
<container xmlns="http://symfony.com/schema/dic/services"
2956+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2957+
xmlns:framework="http://symfony.com/schema/dic/symfony"
2958+
xsi:schemaLocation="http://symfony.com/schema/dic/services
2959+
https://symfony.com/schema/dic/services/services-1.0.xsd
2960+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
2961+
<framework:config>
2962+
<framework:mailer dsn="smtp://localhost:25">
2963+
<framework:envelope>
2964+
<framework:recipients>admin@symfony.com</framework:recipients>
2965+
<framework:recipients>lead@symfony.com</framework:recipients>
2966+
</framework:envelope>
2967+
</framework:mailer>
2968+
</framework:config>
2969+
</container>
2970+
2971+
.. code-block:: php
2972+
// config/packages/mailer.php
2973+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
2974+
return static function (ContainerConfigurator $containerConfigurator): void {
2975+
$containerConfigurator->extension('framework', [
2976+
'mailer' => [
2977+
'dsn' => 'smtp://localhost:25',
2978+
'envelope' => [
2979+
'recipients' => [
2980+
'admin@symfony.com',
2981+
'lead@symfony.com'
2982+
]
2983+
]
2984+
]
2985+
]);
2986+
};
2987+
2988+
.. _mailer-headers:
2989+
2990+
headers
2991+
.......
2992+
2993+
**type**: ``array``
2994+
2995+
Headers to add to emails. key (`name` attribute in xml format) is the header name and value the header value.
2996+
28912997
workflows
28922998
~~~~~~~~~
28932999

0 commit comments

Comments
 (0)