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