@@ -1852,6 +1852,75 @@ 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 :
1870
+ - ' interal@example.com'
1871
+ # you can also use regular expression to define allowed recipients
1872
+ - ' internal-.*@example.(com|fr)'
1873
+
1874
+ .. code-block :: xml
1875
+
1876
+ <!-- config/packages/mailer.xml -->
1877
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1878
+ <container xmlns =" http://symfony.com/schema/dic/services"
1879
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1880
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1881
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1882
+ https://symfony.com/schema/dic/services/services-1.0.xsd
1883
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1884
+
1885
+ <!-- ... -->
1886
+ <framework : config >
1887
+ <framework : mailer >
1888
+ <framework : envelope >
1889
+ <framework : recipient >youremail@example.com</framework : recipient >
1890
+ <framework : allowed-recipient >internal@example.com</framework : allowed-recipient >
1891
+ <!-- you can also use regular expression to define allowed recipients -->
1892
+ <framework : allowed-recipient >internal-.*@example.(com|fr)</framework : allowed-recipient >
1893
+ </framework : envelope >
1894
+ </framework : mailer >
1895
+ </framework : config >
1896
+ </container >
1897
+
1898
+ .. code-block :: php
1899
+
1900
+ // config/packages/mailer.php
1901
+ use Symfony\Config\FrameworkConfig;
1902
+
1903
+ return static function (FrameworkConfig $framework): void {
1904
+ // ...
1905
+ $framework->mailer()
1906
+ ->envelope()
1907
+ ->recipients(['youremail@example.com'])
1908
+ ->allowedRecipients([
1909
+ 'internal@example.com',
1910
+ // you can also use regular expression to define allowed recipients
1911
+ 'internal-.*@example.(com|fr)',
1912
+ ])
1913
+ ;
1914
+ };
1915
+
1916
+ With this configuration, all emails will be sent to ``youremail@example.com ``,
1917
+ except for those sent to ``internal@example.com ``, which will receive emails as
1918
+ usual.
1919
+
1920
+ .. versionadded :: 7.1
1921
+
1922
+ The ``allowed_recipients `` option was introduced in Symfony 7.1.
1923
+
1855
1924
Write a Functional Test
1856
1925
~~~~~~~~~~~~~~~~~~~~~~~
1857
1926
0 commit comments