@@ -40,9 +40,9 @@ The ``$email`` object is created via the :doc:`Mime component </components/mime>
4040Transport
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================== =============================================
4848Service Install with
@@ -55,12 +55,15 @@ Postmark ``composer require symfony/postmark-mailer``
5555SendGrid ``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
98107You 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
0 commit comments