Skip to content

[Mailer] Add the allowed_recipients option #19775

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

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all 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
69 changes: 69 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,75 @@ a specific address, instead of the *real* address:
;
};

You may also go even further by restricting the recipient to a specific
address, except for some specific ones. This can be done by using the
``allowed_recipients`` option:

.. configuration-block::

.. code-block:: yaml

# config/packages/mailer.yaml
when@dev:
framework:
mailer:
envelope:
recipients: ['youremail@example.com']
allowed_recipients:
- 'interal@example.com'
# you can also use regular expression to define allowed recipients
- 'internal-.*@example.(com|fr)'

.. code-block:: xml

<!-- config/packages/mailer.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<!-- ... -->
<framework:config>
<framework:mailer>
<framework:envelope>
<framework:recipient>youremail@example.com</framework:recipient>
<framework:allowed-recipient>internal@example.com</framework:allowed-recipient>
<!-- you can also use regular expression to define allowed recipients -->
<framework:allowed-recipient>internal-.*@example.(com|fr)</framework:allowed-recipient>
</framework:envelope>
</framework:mailer>
</framework:config>
</container>

.. code-block:: php

// config/packages/mailer.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
// ...
$framework->mailer()
->envelope()
->recipients(['youremail@example.com'])
->allowedRecipients([
'internal@example.com',
// you can also use regular expression to define allowed recipients
'internal-.*@example.(com|fr)',
])
;
};

With this configuration, all emails will be sent to ``youremail@example.com``,
except for those sent to ``internal@example.com``, which will receive emails as
usual.

.. versionadded:: 7.1

The ``allowed_recipients`` option was introduced in Symfony 7.1.

Write a Functional Test
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down