Skip to content

Commit 8418e8a

Browse files
committed
Merge branch '4.4'
* 4.4: Mailer doc tweaks Fix sample of use of SYMFONY_DEPRECATIONS_HELPER for regex
2 parents 4de3192 + 33c8372 commit 8418e8a

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

components/mailer.rst

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ The ``$email`` object is created via the :doc:`Mime component </components/mime>
3636
Transport
3737
---------
3838

39-
The only transport that comes pre-installed with mailer is Smtp.
39+
The only transport that comes pre-installed is SMTP.
4040

41-
Below is the list of other popular providers with built in support.
41+
Below is the list of other popular providers with built-in support:
4242

4343
================== =============================================
4444
Service Install with
@@ -51,12 +51,15 @@ Postmark ``composer require symfony/postmark-mailer``
5151
SendGrid ``composer require symfony/sendgrid-mailer``
5252
================== =============================================
5353

54-
For example, suppose you want to use Google's Gmail. First, install it:
54+
For example, suppose you want to use Google's Gmail SMTP server. First, install
55+
it:
5556

5657
.. code-block:: terminal
5758
5859
$ composer require symfony/google-mailer
5960
61+
Then, use the SMTP Gmail transport:
62+
6063
.. code-block:: php
6164
6265
use Symfony\Component\Mailer\Bridge\Google\Smtp\GmailTransport;
@@ -65,30 +68,36 @@ For example, suppose you want to use Google's Gmail. First, install it:
6568
$mailer = new Mailer($transport);
6669
$mailer->send($email);
6770
68-
Use a DSN
69-
---------
71+
Each provider provides up to 3 transports: standard SMTP, HTTP (it uses the
72+
provider's API but the body is created by the mailer component), API (it uses
73+
the full API of the provider with no control over the body creation -- features
74+
might be limited as well).
7075

71-
The mailer component provides a convenient way to create transport object from
72-
DSN string::
76+
.. _mailer_dsn:
77+
78+
The mailer component provides a convenient way to create a transport from a
79+
DSN::
7380

7481
use Symfony\Component\Mailer\Transport;
7582

7683
$transport = Transport::fromDsn($dsn);
7784

78-
Where ``$dsn`` as one of the form below.
79-
80-
- ``smtp://user:pass@gmail``
81-
- ``smtp://key@sendgrid``
82-
- ``smtp://null``
83-
- ``smtp://user:pass@mailgun``
84-
- ``http://key:domain@mailgun``
85-
- ``api://id@postmark``
86-
87-
This provides a unified behavior across all providers.
88-
Easily switch from SMTP in development to a "real" provider in production
89-
with same API.
90-
91-
Failover transport
85+
Where ``$dsn`` depends on the provider you want to use. For plain SMTP, use
86+
``smtp://user:pass@example.com`` or ``smtp://sendmail`` to use the ``sendmail``
87+
binary. For third-party providers, refers to the following table:
88+
89+
==================== ================================== ================================== ================================
90+
Provider SMTP HTTP API
91+
==================== ================================== ================================== ================================
92+
Amazon SES smtp://ACCESS_KEY:SECRET_KEY@ses http://ACCESS_KEY:SECRET_KEY@ses api://ACCESS_KEY:SECRET_KEY@ses
93+
Google Gmail smtp://USERNAME:PASSWORD@gmail n/a n/a
94+
Mailchimp Mandrill smtp://USERNAME:PASSWORD@mandrill http://KEY@mandrill api://KEY@mandrill
95+
Mailgun smtp://USERNAME:PASSWORD@mailgun http://KEY:DOMAIN@mailgun api://KEY:DOMAIN@mailgun
96+
Postmark smtp://ID:ID@postmark n/a api://KEY@postmark
97+
Sendgrid smtp://apikey:KEY@sendgrid n/a api://KEY@sendgrid
98+
==================== ================================== ================================== ================================
99+
100+
Failover Transport
92101
------------------
93102

94103
You can create failover transport with the help of `||` operator::
@@ -106,11 +115,11 @@ you can use the ``&&`` operator between the transports::
106115

107116
$dsn = 'api://id@postmark && smtp://key@sendgrid'
108117

109-
Async
110-
-----
118+
Sending emails asynchronously
119+
-----------------------------
111120

112-
If you want to use the async functionality you need to install the
113-
:doc:`Messenger component </components/messenger>`.
121+
If you want to send emails asynchronously, install the :doc:`Messenger component
122+
</components/messenger>`.
114123

115124
.. code-block:: terminal
116125
@@ -140,11 +149,13 @@ Then, instantiate and pass a ``MessageBus`` as a second argument to ``Mailer``::
140149
]);
141150

142151
$mailer = new Mailer($transport, $bus);
152+
$mailer->send($email);
143153

154+
// you can pass an optional Envelope
144155
$mailer->send($email, new SmtpEnvelope(
145156
new Address('sender@example.com'),
146157
[
147-
new Address('recepient@example.com'),
158+
new Address('recipient@example.com'),
148159
]
149160
));
150161

components/phpunit_bridge.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Running the following command will display the full stack trace:
365365

366366
.. code-block:: terminal
367367
368-
$ SYMFONY_DEPRECATIONS_HELPER='regex=/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
368+
$ SYMFONY_DEPRECATIONS_HELPER='/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
369369
370370
Time-sensitive Tests
371371
--------------------

mailer.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ can deliver emails over ``smtp`` by configuring your ``.env`` file:
2323
# .env
2424
MAILER_DSN=smtp://user:pass@smtp.example.com
2525
26+
.. warning::
27+
28+
If you are migrating from Swiftmailer (and the Swiftmailer bundle), be
29+
warned that the DSN format is different.
30+
2631
Using a 3rd Party Transport
2732
~~~~~~~~~~~~~~~~~~~~~~~~~~~
2833

@@ -70,6 +75,10 @@ options that can be configured with query parameters on end of the ``MAILER_DSN`
7075
like ``?region=`` for Amazon SES. Some transports support sending via ``http``
7176
or ``smtp`` - both work the same, but ``http`` is recommended when available.
7277

78+
.. tip::
79+
80+
Check the :ref:`DSN formats <mailer_dsn>` for all supported providers.
81+
7382
Creating & Sending Messages
7483
---------------------------
7584

0 commit comments

Comments
 (0)