Skip to content

Commit 33c8372

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Mailer doc tweaks Fix sample of use of SYMFONY_DEPRECATIONS_HELPER for regex
2 parents fa30af7 + 5ed2754 commit 33c8372

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
@@ -40,9 +40,9 @@ The ``$email`` object is created via the :doc:`Mime component </components/mime>
4040
Transport
4141
---------
4242

43-
The only transport that comes pre-installed with mailer is Smtp.
43+
The only transport that comes pre-installed is SMTP.
4444

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

4747
================== =============================================
4848
Service Install with
@@ -55,12 +55,15 @@ Postmark ``composer require symfony/postmark-mailer``
5555
SendGrid ``composer require symfony/sendgrid-mailer``
5656
================== =============================================
5757

58-
For example, suppose you want to use Google's Gmail. First, install it:
58+
For example, suppose you want to use Google's Gmail SMTP server. First, install
59+
it:
5960

6061
.. code-block:: terminal
6162
6263
$ composer require symfony/google-mailer
6364
65+
Then, use the SMTP Gmail transport:
66+
6467
.. code-block:: php
6568
6669
use Symfony\Component\Mailer\Bridge\Google\Smtp\GmailTransport;
@@ -69,30 +72,36 @@ For example, suppose you want to use Google's Gmail. First, install it:
6972
$mailer = new Mailer($transport);
7073
$mailer->send($email);
7174
72-
Use a DSN
73-
---------
75+
Each provider provides up to 3 transports: standard SMTP, HTTP (it uses the
76+
provider's API but the body is created by the mailer component), API (it uses
77+
the full API of the provider with no control over the body creation -- features
78+
might be limited as well).
7479

75-
The mailer component provides a convenient way to create transport object from
76-
DSN string::
80+
.. _mailer_dsn:
81+
82+
The mailer component provides a convenient way to create a transport from a
83+
DSN::
7784

7885
use Symfony\Component\Mailer\Transport;
7986

8087
$transport = Transport::fromDsn($dsn);
8188

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

98107
You can create failover transport with the help of `||` operator::
@@ -110,11 +119,11 @@ you can use the ``&&`` operator between the transports::
110119

111120
$dsn = 'api://id@postmark && smtp://key@sendgrid'
112121

113-
Async
114-
-----
122+
Sending emails asynchronously
123+
-----------------------------
115124

116-
If you want to use the async functionality you need to install the
117-
:doc:`Messenger component </components/messenger>`.
125+
If you want to send emails asynchronously, install the :doc:`Messenger component
126+
</components/messenger>`.
118127

119128
.. code-block:: terminal
120129
@@ -144,11 +153,13 @@ Then, instantiate and pass a ``MessageBus`` as a second argument to ``Mailer``::
144153
]);
145154

146155
$mailer = new Mailer($transport, $bus);
156+
$mailer->send($email);
147157

158+
// you can pass an optional Envelope
148159
$mailer->send($email, new SmtpEnvelope(
149160
new Address('sender@example.com'),
150161
[
151-
new Address('recepient@example.com'),
162+
new Address('recipient@example.com'),
152163
]
153164
));
154165

components/phpunit_bridge.rst

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

370370
.. code-block:: terminal
371371
372-
$ SYMFONY_DEPRECATIONS_HELPER='regex=/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
372+
$ SYMFONY_DEPRECATIONS_HELPER='/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
373373
374374
Time-sensitive Tests
375375
--------------------

mailer.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ can deliver emails over ``smtp`` by configuring your ``.env`` file:
2828
# .env
2929
MAILER_DSN=smtp://user:pass@smtp.example.com
3030
31+
.. warning::
32+
33+
If you are migrating from Swiftmailer (and the Swiftmailer bundle), be
34+
warned that the DSN format is different.
35+
3136
Using a 3rd Party Transport
3237
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3338

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

83+
.. tip::
84+
85+
Check the :ref:`DSN formats <mailer_dsn>` for all supported providers.
86+
7887
Creating & Sending Messages
7988
---------------------------
8089

0 commit comments

Comments
 (0)