diff --git a/mailer.rst b/mailer.rst index 9ab2f47c235..5baf9a5d193 100644 --- a/mailer.rst +++ b/mailer.rst @@ -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 + + + + + + + + + + file://%kernel.project_dir%/var/certificates/dkim.pem + symfony.com + s1 + + + %kernel.project_dir%/var/certificates/smime.pem + %kernel.project_dir%/var/certificates/smime.crt + + + + + + + .. 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 ~~~~~~~~~~~~~~~~~~~ @@ -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 + + + + + + + + + + %kernel.project_dir%/var/certificates/smime.crt + + + + + + .. 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