Skip to content

[swiftmailer] Document whitelist option to email redirect #4924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion cookbook/email/dev_environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ can easily achieve this through configuration settings without having to
make any changes to your application's code at all. There are two main
choices when it comes to handling email during development: (a) disabling the
sending of email altogether or (b) sending all email to a specific
address.
address (with optional exceptions).

Disabling Sending
-----------------
Expand Down Expand Up @@ -119,6 +119,51 @@ the replaced address, so you can still see who it would have been sent to.
These are ``X-Swift-Cc`` and ``X-Swift-Bcc`` for the ``CC`` and ``BCC``
addresses respectively.

Sending to a Specified Address, but with exceptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Symfony documentation, the titles follow some special notation. That's why this should be reworded as follows (unless @xabbuh suggest other rewording):

Original:
Sending to a Specified Address, but with exceptions

New:
Sending to a Specified Address but with Exceptions

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Suppose you want to have all email sent to a specific address, instead
of the address actually specified when sending the message (like in the above scenario),
but you want certain email addresses not to be redirected in this way.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has become a very long sentence, let's try to make it a bit shorter. What do you think about?

Suppose you want all emails to be sent to ``dev@example.com``, except
from the emails sent to ``admin@specialdomain.com``. In this case, you
can use the ``delivery_whitelist`` option:

.. configuration-block::

    .. code-block:: yaml

        # app/config/config_dev.yml
        swiftmailer:
            delivery_address: dev@example.com
            delivery_whitelist:
                # all email addresses matching this regex will *not* be
                # redirected to dev@example.com
                - "/@mydomain.com$/"

                # all emails sent to admin@specialdomain.com won't
                # be redirected to dev@example.com too
                - "/^admin@specialdomain.com$/"

    .. code-block:: xml

        <?xml version="1.0" charset="UTF-8" ?>
        <container xmlns="http://symfony.com/schema/dic/services"
            xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
        >
            <swiftmailer:config delivery-address="dev@example.com">
                <!-- all email adress matching this regex will *not* be redirected
                    to dev@example.com -->
                <swiftmailer:delivery-whitelist-pattern>/@mydomain.com$/</swiftmaler:delivery-whitelist-pattern>

                <!-- all emails sent to admin@specialdomain.com won't be
                    redirectd to dev@example.com too -->
                <swiftmailer:delivery-whitelist-pattern>/^admin@specialdomain.com$/</swiftmailer:delivery-whitelist-pattern>
            </swiftmailer:config>

This can be done by adding the ``delivery_whitelist`` option:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please reformat this to only add line breaks after the first word that crosses the 72th character? I.e:

Suppose you normally in your dev environment want to have all email redirected
to a specific address, (like in the above scenario to ``dev@example,com``).
But then you may want email sent to some specific email addresses to go through
after all, and not be redirected (even if it is in the dev environment).  This
can be done by adding the ``delivery_whitelist`` option:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


.. configuration-block::

.. code-block:: yaml

# app/config/config_dev.yml
swiftmailer:
delivery_address: dev@example.com
delivery_whitelist:
- "/@mydomain.com$/"
- "/^admin@specialdomain.com$/"

.. code-block:: xml

<!-- app/config/config_dev.xml -->

<!--
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
http://symfony.com/schema/dic/swiftmailer http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd
-->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should show a full XML config example here (I believe I've put an example in one of my comments in this PR)

<swiftmailer:config delivery-address="dev@example.com" />
<swiftmailer:delivery-whitelist>/@mydomain.com$/</swiftmailer:delivery-whitelist>
<swiftmailer:delivery-whitelist>/^admin@specialdomain.com$/</swiftmailer:delivery-whitelist>
.. code-block:: php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a missing blank line above this line


// app/config/config_dev.php
$container->loadFromExtension('swiftmailer', array(
'delivery_address' => "dev@example.com",
'delivery_whitelist' => array(
'/@mydomain.com$/',
'/^admin@specialdomain.com$/'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we use comma here? i don't know how it is in the documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want a comma there? It is the end of the php array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all array items end with a comma in Symfony CS when using a multiline array. That's to make diffs nicer when adding a new item

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is nitpicking. The code is just an example, and may be used in code not following Symfony CS. But I just changed it, none the less.

),
));

In the above example all mail will be redirected to ``dev@example.com``, except that mail to the single
address ``admin@specialdomain.com`` and all mail to the domain ``mydomain.com`` will be delivered as normal.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done.


Viewing from the Web Debug Toolbar
----------------------------------

Expand Down