Skip to content

Commit 2a9f700

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

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

mailer.rst

+52-1
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

+92
Original file line numberDiff line numberDiff line change
@@ -2819,6 +2819,98 @@ Name of the lock you want to create.
28192819
decorates: lock.invoice.store
28202820
arguments: ['@.inner', 100, 50]
28212821
2822+
mailer
2823+
~~~~~~
2824+
2825+
dsn
2826+
...
2827+
2828+
**type**: ``string``
2829+
2830+
The DSN used by the mailer. When several DSN may be used, use `transports` (see below) instead.
2831+
2832+
transports
2833+
..........
2834+
2835+
**type**: ``array``
2836+
2837+
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.
2838+
2839+
envelope
2840+
........
2841+
2842+
sender
2843+
""""""
2844+
2845+
**type**: ``string``
2846+
2847+
Sender used by the `Mailer`. Keep in mind that this setting override a sender set in the code.
2848+
2849+
recipients
2850+
""""""""""
2851+
2852+
**type**: ``array``
2853+
2854+
Recipients used by the `Mailer`. Keep in mind that this setting override recipients set in the code.
2855+
2856+
.. configuration-block::
2857+
2858+
.. code-block:: yaml
2859+
2860+
# config/packages/mailer.yaml
2861+
framework:
2862+
mailer:
2863+
dsn: 'smtp://localhost:25'
2864+
envelope:
2865+
recipients: ['admin@symfony.com', 'lead@symfony.com']
2866+
2867+
.. code-block:: xml
2868+
2869+
<!-- config/packages/mailer.xml -->
2870+
<?xml version="1.0" encoding="UTF-8" ?>
2871+
<container xmlns="http://symfony.com/schema/dic/services"
2872+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2873+
xmlns:framework="http://symfony.com/schema/dic/symfony"
2874+
xsi:schemaLocation="http://symfony.com/schema/dic/services
2875+
https://symfony.com/schema/dic/services/services-1.0.xsd
2876+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
2877+
2878+
<framework:config>
2879+
<framework:mailer dsn="smtp://localhost:25">
2880+
<framework:envelope>
2881+
<framework:recipient>admin@symfony.com</framework:recipient>
2882+
<framework:recipient>lead@symfony.com</framework:recipient>
2883+
</framework:envelope>
2884+
</framework:mailer>
2885+
</framework:config>
2886+
</container>
2887+
2888+
.. code-block:: php
2889+
2890+
// config/packages/mailer.php
2891+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
2892+
2893+
return static function (ContainerConfigurator $containerConfigurator): void {
2894+
$containerConfigurator->extension('framework', [
2895+
'mailer' => [
2896+
'dsn' => 'smtp://localhost:25',
2897+
'envelope' => [
2898+
'recipients' => [
2899+
'admin@symfony.com',
2900+
'lead@symfony.com'
2901+
]
2902+
]
2903+
]
2904+
]);
2905+
};
2906+
2907+
headers
2908+
.......
2909+
2910+
**type**: ``array``
2911+
2912+
Headers to add to emails. key (`name` attribute in xml format) is the header name and value the header value.
2913+
28222914
workflows
28232915
~~~~~~~~~
28242916

0 commit comments

Comments
 (0)