Skip to content

Commit 9cce63c

Browse files
committed
feature #4924 [swiftmailer] Document whitelist option to email redirect (TerjeBr)
This PR was submitted for the 2.6 branch but it was merged into the 2.3 branch instead (closes #4924). Discussion ---------- [swiftmailer] Document whitelist option to email redirect The redirectPlugin in switfmailer allows you to specify a white-list of regex's that matches email addresses that are still sent to, when redirecting all email to one address. Code was added in PR [switfmailer/SwiftmailerBundle#19](symfony/swiftmailer-bundle#19) Commits ------- 1448f58 More xml fixes 16907ed Xml changes and line-break changes 747199c Swiched mydomain and specialdomain c35a26f Changes recommended by @cordoval 8c1da8a Changes recommended by @javierguiluz 4aa58a4 Changed line-breaks in text 217811d Added improvments from @wouterj a4af6a0 fixed typo in "except" 6f64fdb Document whitelist option to email redirect
2 parents 9fab10b + 1448f58 commit 9cce63c

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

cookbook/email/dev_environment.rst

+62-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ can easily achieve this through configuration settings without having to
1111
make any changes to your application's code at all. There are two main
1212
choices when it comes to handling email during development: (a) disabling the
1313
sending of email altogether or (b) sending all email to a specific
14-
address.
14+
address (with optional exceptions).
1515

1616
Disabling Sending
1717
-----------------
@@ -119,6 +119,67 @@ the replaced address, so you can still see who it would have been sent to.
119119
These are ``X-Swift-Cc`` and ``X-Swift-Bcc`` for the ``CC`` and ``BCC``
120120
addresses respectively.
121121

122+
Sending to a Specified Address but with Exceptions
123+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124+
125+
Suppose you want to have all email redirected to a specific address,
126+
(like in the above scenario to ``[email protected]``). But then you may want
127+
email sent to some specific email addresses to go through after all, and
128+
not be redirected (even if it is in the dev environment). This can be done
129+
by adding the ``delivery_whitelist`` option:
130+
131+
.. configuration-block::
132+
133+
.. code-block:: yaml
134+
135+
# app/config/config_dev.yml
136+
swiftmailer:
137+
delivery_address: [email protected]
138+
delivery_whitelist:
139+
# all email addresses matching this regex will *not* be
140+
# redirected to [email protected]
141+
- "/@specialdomain.com$/"
142+
143+
# all emails sent to [email protected] won't
144+
# be redirected to [email protected] too
145+
146+
147+
.. code-block:: xml
148+
149+
<!-- app/config/config_dev.xml -->
150+
151+
<?xml version="1.0" charset="UTF-8" ?>
152+
<container xmlns="http://symfony.com/schema/dic/services"
153+
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer">
154+
155+
<swiftmailer:config delivery-address="[email protected]">
156+
<!-- all email addresses matching this regex will *not* be redirected to [email protected] -->
157+
<swiftmailer:delivery-whitelist-pattern>/@specialdomain.com$/</swiftmailer:delivery-whitelist-pattern>
158+
159+
<!-- all emails sent to [email protected] won't be redirected to [email protected] too -->
160+
<swiftmailer:delivery-whitelist-pattern>/^[email protected]$/</swiftmailer:delivery-whitelist-pattern>
161+
</swiftmailer:config>
162+
163+
.. code-block:: php
164+
165+
// app/config/config_dev.php
166+
$container->loadFromExtension('swiftmailer', array(
167+
'delivery_address' => "[email protected]",
168+
'delivery_whitelist' => array(
169+
// all email addresses matching this regex will *not* be
170+
// redirected to [email protected]
171+
'/@specialdomain.com$/',
172+
173+
// all emails sent to [email protected] won't be
174+
// redirected to [email protected] too
175+
176+
),
177+
));
178+
179+
In the above example all email messages will be redirected to ``[email protected]``,
180+
except messages sent to the ``[email protected]`` address or to any email
181+
address belonging to the domain ``specialdomain.com``, which will be delivered as normal.
182+
122183
Viewing from the Web Debug Toolbar
123184
----------------------------------
124185

0 commit comments

Comments
 (0)