Skip to content

Commit 45b7549

Browse files
Add configuration to the mailer section #20641
#20641
1 parent 15cddbe commit 45b7549

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

mailer.rst

+123
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,78 @@ key but not a certificate::
13701370
->toArray()
13711371
);
13721372

1373+
Signing Messages Globally
1374+
.........................
1375+
1376+
Instead of creating a signer instance for every email, you can configure a global signer
1377+
that automatically applies to all outgoing messages. This approach reduces repetition
1378+
and centralizes your configuration for both DKIM and S/MIME signing.
1379+
1380+
.. configuration-block::
1381+
1382+
.. code-block:: yaml
1383+
1384+
# config/packages/mailer.yaml
1385+
framework:
1386+
mailer:
1387+
dkim_signer:
1388+
key: 'file://%kernel.project_dir%/var/certificates/dkim.pem'
1389+
domain: 'symfony.com'
1390+
select: 's1'
1391+
smime_signer:
1392+
key: '%kernel.project_dir%/var/certificates/smime.key'
1393+
certificate: '%kernel.project_dir%/var/certificates/smime.crt'
1394+
passphrase: ''
1395+
1396+
.. code-block:: xml
1397+
1398+
<!-- config/packages/mailer.xml -->
1399+
<?xml version="1.0" encoding="UTF-8" ?>
1400+
<container xmlns="http://symfony.com/schema/dic/services"
1401+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1402+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1403+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1404+
https://symfony.com/schema/dic/services/services-1.0.xsd
1405+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1406+
1407+
<!-- ... -->
1408+
<framework:config>
1409+
<framework:mailer>
1410+
<framework:dkim-signer>
1411+
<framework:key>file://%kernel.project_dir%/var/certificates/dkim.pem</framework:key>
1412+
<framework:domain>symfony.com</framework:domain>
1413+
<framework:select>s1</framework:select>
1414+
</framework:dkim-signer>
1415+
<framework:smime-signer>
1416+
<framework:key>%kernel.project_dir%/var/certificates/smime.pem</framework:key>
1417+
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
1418+
<framework:passphrase></framework:passphrase>
1419+
</framework:smime-signer>
1420+
</framework:mailer>
1421+
</framework:config>
1422+
</container>
1423+
1424+
.. code-block:: php
1425+
1426+
// config/packages/mailer.php
1427+
use Symfony\Config\FrameworkConfig;
1428+
1429+
return static function (FrameworkConfig $framework): void {
1430+
$mailer = $framework->mailer();
1431+
$mailer->dsn('%env(MAILER_DSN)%');
1432+
$mailer->dkimSigner()
1433+
->key('file://%kernel.project_dir%/var/certificates/dkim.pem')
1434+
->domain('symfony.com')
1435+
->select('s1');
1436+
1437+
$mailer->smimeSigner()
1438+
->key('%kernel.project_dir%/var/certificates/smime.key')
1439+
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
1440+
->passphrase('')
1441+
;
1442+
};
1443+
1444+
13731445
Encrypting Messages
13741446
~~~~~~~~~~~~~~~~~~~
13751447

@@ -1411,6 +1483,57 @@ and it will select the appropriate certificate depending on the ``To`` option::
14111483
$firstEncryptedEmail = $encrypter->encrypt($firstEmail);
14121484
$secondEncryptedEmail = $encrypter->encrypt($secondEmail);
14131485

1486+
1487+
Encrypting Messages Globally
1488+
............................
1489+
1490+
Similarly, you can avoid instantiating a new encrypter for every email by setting up a
1491+
global S/MIME encrypter. With this configuration, the encrypter is automatically
1492+
applied to all emails you send.
1493+
1494+
.. configuration-block::
1495+
1496+
.. code-block:: yaml
1497+
1498+
# config/packages/mailer.yaml
1499+
framework:
1500+
mailer:
1501+
smime_encrypter:
1502+
certificate: '%kernel.project_dir%/var/certificates/smime.crt'
1503+
1504+
.. code-block:: xml
1505+
1506+
<!-- config/packages/mailer.xml -->
1507+
<?xml version="1.0" encoding="UTF-8" ?>
1508+
<container xmlns="http://symfony.com/schema/dic/services"
1509+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1510+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1511+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1512+
https://symfony.com/schema/dic/services/services-1.0.xsd
1513+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1514+
1515+
<!-- ... -->
1516+
<framework:config>
1517+
<framework:mailer>
1518+
<framework:smime-encrypter>
1519+
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
1520+
</framework:smime-encrypter>
1521+
</framework:mailer>
1522+
</framework:config>
1523+
</container>
1524+
1525+
.. code-block:: php
1526+
1527+
// config/packages/mailer.php
1528+
use Symfony\Config\FrameworkConfig;
1529+
1530+
return static function (FrameworkConfig $framework): void {
1531+
$mailer = $framework->mailer();
1532+
$mailer->smimeEncrypter()
1533+
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
1534+
;
1535+
};
1536+
14141537
.. _multiple-email-transports:
14151538

14161539
Multiple Email Transports

0 commit comments

Comments
 (0)