@@ -1852,6 +1852,66 @@ a specific address, instead of the *real* address:
1852
1852
;
1853
1853
};
1854
1854
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
+
1855
1915
Write a Functional Test
1856
1916
~~~~~~~~~~~~~~~~~~~~~~~
1857
1917
0 commit comments