Skip to content

Commit 75c51ba

Browse files
committed
minor #12495 [Mailer] Move to the new DSN format (fabpot, javiereguiluz, tucksaun)
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Move to the new DSN format Documents symfony/symfony#33424 Cherry-picking #12258 that should have target 4.4 and also add a missing DSN update. Commits ------- a2c607b [Mailer] Move remaining DSN to new format ca56502 Minor tweaks be392bc Move to the new DSN format for Mailer
2 parents 27de64b + a2c607b commit 75c51ba

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed

components/mailer.rst

+31-15
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,35 @@ DSN::
8585
$transport = Transport::fromDsn($dsn);
8686

8787
Where ``$dsn`` depends on the provider you want to use. For plain SMTP, use
88-
``smtp://user:pass@example.com`` or ``smtp://sendmail`` to use the ``sendmail``
89-
binary. For third-party providers, refers to the following table:
90-
91-
==================== ================================== ================================== ================================
92-
Provider SMTP HTTP API
93-
==================== ================================== ================================== ================================
94-
Amazon SES smtp://ACCESS_KEY:SECRET_KEY@ses http://ACCESS_KEY:SECRET_KEY@ses api://ACCESS_KEY:SECRET_KEY@ses
95-
Google Gmail smtp://USERNAME:PASSWORD@gmail n/a n/a
96-
Mailchimp Mandrill smtp://USERNAME:PASSWORD@mandrill http://KEY@mandrill api://KEY@mandrill
97-
Mailgun smtp://USERNAME:PASSWORD@mailgun http://KEY:DOMAIN@mailgun api://KEY:DOMAIN@mailgun
98-
Postmark smtp://ID:ID@postmark n/a api://KEY@postmark
99-
Sendgrid smtp://apikey:KEY@sendgrid n/a api://KEY@sendgrid
100-
==================== ================================== ================================== ================================
88+
``smtp://user:pass@example.com`` or ``sendmail+smtp://default`` to use the
89+
``sendmail`` binary. To disable the transport, use ``null://null``.
90+
91+
For third-party providers, refer to the following table:
92+
93+
==================== ========================================== =========================================== ========================================
94+
Provider SMTP HTTP API
95+
==================== ========================================== =========================================== ========================================
96+
Amazon SES ses+smtp://ACCESS_KEY:SECRET_KEY@default ses+https://ACCESS_KEY:SECRET_KEY@default ses+api://ACCESS_KEY:SECRET_KEY@default
97+
Google Gmail gmail+smtp://USERNAME:PASSWORD@default n/a n/a
98+
Mailchimp Mandrill mandrill+smtp://USERNAME:PASSWORD@default mandrill+https://KEY@default mandrill+api://KEY@default
99+
Mailgun mailgun+smtp://USERNAME:PASSWORD@default mailgun+https://KEY:DOMAIN@default mailgun+api://KEY:DOMAIN@default
100+
Postmark postmark+smtp://ID:ID@default n/a postmark+api://KEY@default
101+
Sendgrid sendgrid+smtp://apikey:KEY@default n/a sendgrid+api://KEY@default
102+
==================== ========================================== =========================================== ========================================
103+
104+
Instead of choosing a specific protocol, you can also let Symfony pick the
105+
best one by omitting it from the scheme: for instance, ``mailgun://KEY:DOMAIN@default``
106+
is equivalent to ``mailgun+https://KEY:DOMAIN@default``.
107+
108+
If you want to override the default host for a provider (to debug an issue using
109+
a service like ``requestbin.com``), change ``default`` by your host:
110+
111+
.. code-block:: bash
112+
113+
mailgun+https://KEY:DOMAIN@example.com
114+
mailgun+https://KEY:DOMAIN@example.com:99
115+
116+
Note that the protocol is *always* HTTPs and cannot be changed.
101117

102118
High Availability
103119
-----------------
@@ -108,7 +124,7 @@ to ensure that emails are sent even if one mailer server fails .
108124
A failover transport is configured with two or more transports and the
109125
``failover`` keyword::
110126

111-
$dsn = 'failover(api://id@postmark smtp://key@sendgrid)';
127+
$dsn = 'failover(postmark+api://ID@default sendgrid+smtp://KEY@default)';
112128

113129
The mailer will start using the first transport. If the sending fails, the
114130
mailer won't retry it with the other transports, but it will switch to the next
@@ -123,7 +139,7 @@ to distribute the mailing workload across multiple transports .
123139
A round-robin transport is configured with two or more transports and the
124140
``roundrobin`` keyword::
125141

126-
$dsn = 'roundrobin(api://id@postmark smtp://key@sendgrid)'
142+
$dsn = 'roundrobin(postmark+api://ID@default sendgrid+smtp://KEY@default)'
127143

128144
The mailer will start using the first transport and if it fails, it will retry
129145
the same delivery with the next transports until one of them succeeds (or until

mailer.rst

+18-11
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,28 @@ You'll now have a new line in your ``.env`` file that you can uncomment:
6464
6565
# .env
6666
SENDGRID_KEY=
67-
MAILER_DSN=smtp://$SENDGRID_KEY@sendgrid
67+
MAILER_DSN=sendgrid://$SENDGRID_KEY@default
6868
69-
The ``MAILER_DSN`` isn't a *real* SMTP address: it's a simple format that offloads
70-
most of the configuration work to mailer. The ``@sendgrid`` part of the address
71-
activates the SendGrid mailer library that you just installed, which knows all
72-
about how to deliver messages to SendGrid.
69+
The ``MAILER_DSN`` isn't a *real* address: it's a simple format that offloads
70+
most of the configuration work to mailer. The ``sendgrid`` scheme activates the
71+
SendGrid provider that you just installed, which knows all about how to deliver
72+
messages to SendGrid.
7373

7474
The *only* part you need to change is to set ``SENDGRID_KEY`` to your key (in
7575
``.env`` or ``.env.local``).
7676

77-
Each transport will have different environment variables that the library will use
78-
to configure the *actual* address and authentication for delivery. Some also have
79-
options that can be configured with query parameters on end of the ``MAILER_DSN`` -
80-
like ``?region=`` for Amazon SES. Some transports support sending via ``http``
81-
or ``smtp`` - both work the same, but ``http`` is recommended when available.
77+
Each provider has different environment variables that the Mailer uses to
78+
configure the *actual* protocol, address and authentication for delivery. Some
79+
also have options that can be configured with query parameters at the end of the
80+
``MAILER_DSN`` - like ``?region=`` for Amazon SES. Some providers support
81+
sending via ``http``, ``api`` or ``smtp``. Symfony chooses the best available
82+
transport, but you can force to use one:
83+
84+
.. code-block:: bash
85+
86+
# .env
87+
# force to use SMTP instead of HTTP (which is the default)
88+
MAILER_DSN=sendgrid+smtp://$SENDGRID_KEY@default
8289
8390
.. tip::
8491

@@ -742,7 +749,7 @@ environment:
742749
# config/packages/dev/mailer.yaml
743750
framework:
744751
mailer:
745-
dsn: 'smtp://null'
752+
dsn: 'null://null'
746753
747754
.. note::
748755

0 commit comments

Comments
 (0)