Skip to content

Commit a0cdefe

Browse files
committed
minor #13784 Mailer tweaks (fabpot)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Mailer tweaks <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 35c22c1 Mailer tweaks
2 parents 5bf187e + 35c22c1 commit a0cdefe

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

mailer.rst

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ integration, CSS inlining, file attachments and a lot more. Get them installed w
2020
Transport Setup
2121
---------------
2222

23-
Emails are delivered via a "transport". And without installing anything else, you
24-
can deliver emails over ``smtp`` by configuring your ``.env`` file (the
25-
``user``, ``pass`` and ``port`` parameters are optional):
23+
Emails are delivered via a "transport". Out of the box, you can deliver emails
24+
over ``SMTP`` by configuring your ``.env`` file (the ``user``, ``pass`` and
25+
``port`` parameters are optional):
2626

2727
.. code-block:: bash
2828
@@ -37,8 +37,8 @@ can deliver emails over ``smtp`` by configuring your ``.env`` file (the
3737
Using a 3rd Party Transport
3838
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939

40-
But an easier option is to send emails via a 3rd party provider. Mailer supports
41-
several - install whichever you want:
40+
Instead of using your own SMTP server, you can send emails via a 3rd party
41+
provider. Mailer supports several - install whichever you want:
4242

4343
================== =============================================
4444
Service Install with
@@ -52,7 +52,7 @@ SendGrid ``composer require symfony/sendgrid-mailer``
5252
================== =============================================
5353

5454
Each library includes a :ref:`Symfony Flex recipe <symfony-flex>` that will add
55-
example configuration to your ``.env`` file. For example, suppose you want to
55+
a configuration example to your ``.env`` file. For example, suppose you want to
5656
use SendGrid. First, install it:
5757

5858
.. code-block:: terminal
@@ -66,13 +66,11 @@ You'll now have a new line in your ``.env`` file that you can uncomment:
6666
# .env
6767
MAILER_DSN=sendgrid://KEY@default
6868
69-
The ``MAILER_DSN`` isn't a *real* address: it's a simple format that offloads
70-
most of the configuration work to mailer. The ``sendgrid`` scheme activates the
71-
SendGrid provider that you just installed, which knows all about how to deliver
72-
messages to SendGrid.
73-
74-
The *only* part you need to change is to replace ``KEY`` in the ``MAILER_DSN`` (in
75-
``.env`` or ``.env.local``).
69+
The ``MAILER_DSN`` isn't a *real* address: it's a convenient format that
70+
offloads most of the configuration work to mailer. The ``sendgrid`` scheme
71+
activates the SendGrid provider that you just installed, which knows all about
72+
how to deliver messages via SendGrid. The *only* part you need to change is the
73+
``KEY`` placeholder.
7674

7775
Each provider has different environment variables that the Mailer uses to
7876
configure the *actual* protocol, address and authentication for delivery. Some
@@ -95,8 +93,8 @@ Creating & Sending Messages
9593
---------------------------
9694

9795
To send an email, autowire the mailer using
98-
:class:`Symfony\\Component\\Mailer\\MailerInterface` (service id ``mailer.mailer``)
99-
and create an :class:`Symfony\\Component\\Mime\\Email` object::
96+
:class:`Symfony\\Component\\Mailer\\MailerInterface` and create an
97+
:class:`Symfony\\Component\\Mime\\Email` object::
10098

10199
// src/Controller/MailerController.php
102100
namespace App\Controller;
@@ -129,7 +127,7 @@ and create an :class:`Symfony\\Component\\Mime\\Email` object::
129127
}
130128
}
131129

132-
That's it! The message will be sent via whatever transport you configured.
130+
That's it! The message will be sent via the transport you configured.
133131

134132
Email Addresses
135133
~~~~~~~~~~~~~~~
@@ -793,20 +791,15 @@ Always Send to the same Address
793791
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
794792

795793
Instead of disabling delivery entirely, you might want to *always* send emails to
796-
a specific address, instead of the *real* address. To do that, you can take
797-
advantage of the ``EnvelopeListener`` and register it *only* for the ``dev``
798-
environment:
794+
a specific address, instead of the *real* address:
799795

800796
.. code-block:: yaml
801797
802-
# config/services_dev.yaml
803-
services:
804-
mailer.dev.set_recipients:
805-
class: Symfony\Component\Mailer\EventListener\EnvelopeListener
806-
tags: ['kernel.event_subscriber']
807-
arguments:
808-
$sender: null
809-
$recipients: ['youremail@example.com']
798+
# config/packages/dev/mailer.yaml
799+
framework:
800+
mailer:
801+
envelope:
802+
recipients: ['youremail@example.com']
810803
811804
.. _`download the foundation-emails.css file`: https://github.com/foundation/foundation-emails/blob/develop/dist/foundation-emails.css
812805
.. _`league/html-to-markdown`: https://github.com/thephpleague/html-to-markdown

0 commit comments

Comments
 (0)