Skip to content
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
31 changes: 28 additions & 3 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@
framework:
mailer:
smime_encrypter:
certificate: '%kernel.project_dir%/var/certificates/smime.crt'
repository: app.my_smime_encrypter

Check failure on line 1535 in mailer.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In CheckExceptionOnInvalidReferenceBehaviorPass.php line 116: The service "mailer.smime_encrypter.listener" has a dependency on a non-exi stent service "app.my_smime_encrypter".

.. code-block:: xml

Expand All @@ -1549,7 +1549,7 @@
<framework:config>
<framework:mailer>
<framework:smime-encrypter>
<framework:certificate>%kernel.project_dir%/var/certificates/smime.crt</framework:certificate>
<framework:repository>app.my_smime_encrypter</framework:repository>
</framework:smime-encrypter>
</framework:mailer>
</framework:config>
Expand All @@ -1563,10 +1563,35 @@
return static function (FrameworkConfig $framework): void {
$mailer = $framework->mailer();
$mailer->smimeEncrypter()
->certificate('%kernel.project_dir%/var/certificates/smime.crt')
->repository('app.my_smime_encrypter')
;
};

Check failure on line 1568 in mailer.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In CheckExceptionOnInvalidReferenceBehaviorPass.php line 116: The service "mailer.smime_encrypter.listener" has a dependency on a non-exi stent service "app.my_smime_encrypter".

The ``repository`` option must be a service ID that implements
:class:`Symfony\\Component\\Mailer\\EventListener\\SmimeCertificateRepositoryInterface`::

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the method SmimeCertificateRepositoryInterface::findCertificatePathFor is to resolve the certificate file path for a given email address, as the S/MIME encrypter expects a valid local file path to the certificate.

namespace App\Security;

use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mailer\EventListener\SmimeCertificateRepositoryInterface;

class LocalFileCertificateRepository implements SmimeCertificateRepositoryInterface
{
public function __construct(
#[Autowire(param: 'kernel.project_dir')]
private readonly string $projectDir
){}

public function findCertificatePathFor(string $email): ?string
{
$hash = hash('sha256', strtolower(trim($email)));
$path = sprintf('%s/storage/%s.crt', $this->projectDir, $hash);

return file_exists($path) ? $path : null;
}
}


.. versionadded:: 7.3

Global message encryption configuration was introduced in Symfony 7.3.
Expand Down
Loading