Skip to content

Commit a3097df

Browse files
committed
updated the mailer docs
1 parent d882d2d commit a3097df

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

components/mailer.rst

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

44-
The only transport that comes pre-installed with mailer is Smtp.
44+
The only transport that comes pre-installed is SMTP.
4545

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

4848
================== =============================================
4949
Service Install with
@@ -56,12 +56,15 @@ Postmark ``composer require symfony/postmark-mailer``
5656
SendGrid ``composer require symfony/sendgrid-mailer``
5757
================== =============================================
5858

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

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

76-
The mailer component provides a convenient way to create transport object from
77-
DSN string::
81+
.. _mailer_dsn:
82+
83+
The mailer component provides a convenient way to create a transport from a
84+
DSN::
7885

7986
use Symfony\Component\Mailer\Transport;
8087

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

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

99108
You can create failover transport with the help of `||` operator::
@@ -111,11 +120,11 @@ you can use the ``&&`` operator between the transports::
111120

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

114-
Async
115-
-----
123+
Sending emails asynchronously
124+
-----------------------------
116125

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

120129
.. code-block:: terminal
121130
@@ -145,11 +154,13 @@ Then, instantiate and pass a ``MessageBus`` as a second argument to ``Mailer``::
145154
]);
146155

147156
$mailer = new Mailer($transport, $bus);
157+
$mailer->send($email);
148158

159+
// you can pass an optional Envelope
149160
$mailer->send($email, new SmtpEnvelope(
150161
new Address('sender@example.com'),
151162
[
152-
new Address('recepient@example.com'),
163+
new Address('recipient@example.com'),
153164
]
154165
));
155166

mailer.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ options that can be configured with query parameters on end of the ``MAILER_DSN`
8585
like ``?region=`` for Amazon SES. Some transports support sending via ``http``
8686
or ``smtp`` - both work the same, but ``http`` is recommended when available.
8787

88+
.. tip::
89+
90+
Check the :ref:`DSN formats <mailer_dsn>` for all supported providers.
91+
8892
Creating & Sending Messages
8993
---------------------------
9094

0 commit comments

Comments
 (0)