@@ -41,9 +41,9 @@ The ``$email`` object is created via the :doc:`Mime component </components/mime>
41
41
Transport
42
42
---------
43
43
44
- The only transport that comes pre-installed with mailer is Smtp .
44
+ The only transport that comes pre-installed is SMTP .
45
45
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:
47
47
48
48
================== =============================================
49
49
Service Install with
@@ -56,12 +56,15 @@ Postmark ``composer require symfony/postmark-mailer``
56
56
SendGrid ``composer require symfony/sendgrid-mailer ``
57
57
================== =============================================
58
58
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:
60
61
61
62
.. code-block :: terminal
62
63
63
64
$ composer require symfony/google-mailer
64
65
66
+ Then, use the SMTP Gmail transport:
67
+
65
68
.. code-block :: php
66
69
67
70
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:
70
73
$mailer = new Mailer($transport);
71
74
$mailer->send($email);
72
75
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).
75
80
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::
78
85
79
86
use Symfony\Component\Mailer\Transport;
80
87
81
88
$transport = Transport::fromDsn($dsn);
82
89
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
97
106
------------------
98
107
99
108
You can create failover transport with the help of `|| ` operator::
@@ -111,11 +120,11 @@ you can use the ``&&`` operator between the transports::
111
120
112
121
$dsn = 'api://id@postmark && smtp://key@sendgrid'
113
122
114
- Async
115
- -----
123
+ Sending emails asynchronously
124
+ -----------------------------
116
125
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>`.
119
128
120
129
.. code-block :: terminal
121
130
@@ -145,11 +154,13 @@ Then, instantiate and pass a ``MessageBus`` as a second argument to ``Mailer``::
145
154
]);
146
155
147
156
$mailer = new Mailer($transport, $bus);
157
+ $mailer->send($email);
148
158
159
+ // you can pass an optional Envelope
149
160
$mailer->send($email, new SmtpEnvelope(
150
161
new Address('sender@example.com'),
151
162
[
152
- new Address('recepient @example.com'),
163
+ new Address('recipient @example.com'),
153
164
]
154
165
));
155
166
0 commit comments