Skip to content

Commit d87be4e

Browse files
committed
minor #20689 [Mailer] Add configuration to the mailer section (eliasfernandez)
This PR was merged into the 7.3 branch. Discussion ---------- [Mailer] Add configuration to the mailer section closes #20641 Commits ------- 45b7549 Add configuration to the mailer section #20641
2 parents 07e3d4b + 45b7549 commit d87be4e

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
@@ -1364,6 +1364,78 @@ key but not a certificate::
13641364
->toArray()
13651365
);
13661366

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

@@ -1405,6 +1477,57 @@ and it will select the appropriate certificate depending on the ``To`` option::
14051477
$firstEncryptedEmail = $encrypter->encrypt($firstEmail);
14061478
$secondEncryptedEmail = $encrypter->encrypt($secondEmail);
14071479

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

14101533
Multiple Email Transports

0 commit comments

Comments
 (0)