@@ -36,9 +36,9 @@ The ``$email`` object is created via the :doc:`Mime component </components/mime>
3636Transport
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================== =============================================
4444Service Install with
@@ -51,12 +51,15 @@ Postmark ``composer require symfony/postmark-mailer``
5151SendGrid ``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
94103You 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
0 commit comments