8000 [Mailer] Add the `allowed_recipients` option · symfony/symfony-docs@a7cdac4 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7cdac4

Browse files
[Mailer] Add the allowed_recipients option
1 parent e801d38 commit a7cdac4

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

mailer.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,66 @@ a specific address, instead of the *real* address:
18521852
;
18531853
};
18541854
1855+
You may also go even further by restricting the recipient to a specific
1856+
address, except for some specific ones. This can be done by using the
1857+
``allowed_recipients`` option:
1858+
1859+
.. configuration-block::
1860+
1861+
.. code-block:: yaml
1862+
1863+
# config/packages/mailer.yaml
1864+
when@dev:
1865+
framework:
1866+
mailer:
1867+
envelope:
1868+
recipients: ['youremail@example.com']
1869+
allowed_recipients: ['internal@example.com']
1870+
1871+
.. code-block:: xml
1872+
1873+
<!-- config/packages/mailer.xml -->
1874+
<?xml version="1.0" encoding="UTF-8" ?>
1875+
<container xmlns="http://symfony.com/schema/dic/services"
1876+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1877+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1878+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1879+
https://symfony.com/schema/dic/services/services-1.0.xsd
1880+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1881+
1882+
<!-- ... -->
1883+
<framework:config>
1884+
<framework:mailer>
1885+
<framework:envelope>
1886+
<framework:recipient>youremail@example.com</framework:recipient>
1887+
<framework:allowed-recipient>internal@example.com</framework:allowed-recipient>
1888+
</framework:envelope>
1889+
</framework:mailer>
1890+
</framework:config>
1891+
</container>
1892+
1893+
.. code-block:: php
1894+
1895+
// config/packages/mailer.php
1896+
use Symfony\Config\FrameworkConfig;
1897+
1898+
return static function (FrameworkConfig $framework): void {
1899+
// ...
1900+
$framework->mailer()
1901+
->envelope()
1902+
->recipients(['youremail@example.com'])
1903+
->allowedRecipients(['internal@example.com'])
1904+
;
1905+
};
1906+
1907+
With this configuration, all emails will be sent to ``youremail@example.com``,
1908+
except for those sent to ``internal@example.com``, which will receive emails as
1909+
usual.
1910+
1911+
.. versionadded:: 7.1
1912+
1913+
The ``allowed_recipients`` option was introduced in Symfony 7.1.
1914+
18551915
Write a Functional Test
18561916
~~~~~~~~~~~~~~~~~~~~~~~
18571917

0 commit comments

Comments
 (0)
0