Skip to content

[Mailer] Add configuration to the mailer section #20689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,78 @@ key but not a certificate::
->toArray()
);

Signing Messages Globally
.........................

Instead of creating a signer instance for every email, you can configure a global signer
that automatically applies to all outgoing messages. This approach reduces repetition
and centralizes your configuration for both DKIM and S/MIME signing.

.. configuration-block::

.. code-block:: yaml

# config/packages/mailer.yaml
framework:
mailer:
dkim_signer:
key: 'file://%kernel.project_dir%/var/certificates/dkim.pem'
domain: 'symfony.com'
select: 's1'
smime_signer:
key: '%kernel.project_dir%/var/certificates/smime.key'
certificate: '%kernel.project_dir%/var/certificates/smime.crt'
passphrase: ''

.. code-block:: xml

<!-- config/packages/mailer.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<!-- ... -->
<framework:config>
<framework:mailer>
<framework:dkim-signer>
<framework:key>file://%kernel.project_dir%/var/certificates/dkim.pem</framework:key>
<framework:domain>symfony.com</framework:domain>
<framework:select>s1</framework:select>
</framework:dkim-signer>
<framework:smime-signer>
<framework:key>%kernel.project_dir%/var/certificates/smime.pem</framework:key>
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
<framework:passphrase></framework:passphrase>
</framework:smime-signer>
</framework:mailer>
</framework:config>
</container>

.. code-block:: php

// config/packages/mailer.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
$mailer = $framework->mailer();
$mailer->dsn('%env(MAILER_DSN)%');
$mailer->dkimSigner()
->key('file://%kernel.project_dir%/var/certificates/dkim.pem')
->domain('symfony.com')
->select('s1');

$mailer->smimeSigner()
->key('%kernel.project_dir%/var/certificates/smime.key')
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
->passphrase('')
;
};


Encrypting Messages
~~~~~~~~~~~~~~~~~~~

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


Encrypting Messages Globally
............................

Similarly, you can avoid instantiating a new encrypter for every email by setting up a
global S/MIME encrypter. With this configuration, the encrypter is automatically
applied to all emails you send.

.. configuration-block::

.. code-block:: yaml

# config/packages/mailer.yaml
framework:
mailer:
smime_encrypter:
certificate: '%kernel.project_dir%/var/certificates/smime.crt'

.. code-block:: xml

<!-- config/packages/mailer.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<!-- ... -->
<framework:config>
<framework:mailer>
<framework:smime-encrypter>
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
</framework:smime-encrypter>
</framework:mailer>
</framework:config>
</container>

.. code-block:: php

// config/packages/mailer.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
$mailer = $framework->mailer();
$mailer->smimeEncrypter()
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
;
};

.. _multiple-email-transports:

Multiple Email Transports
Expand Down