Feature: #97747 - Introduce MailerInterface 

See forge#97747

Description 

To be able to use your own custom mailer implementation in the TYPO3 Core, an interface \TYPO3\CMS\Core\Mail\MailerInterface is introduced, which extends \Symfony\Component\Mailer\MailerInterface

By default, \TYPO3\CMS\Core\Mail\Mailer is registered as implementation in Configuration/Services.yaml.

Example 

use TYPO3\CMS\Core\Mail\MailerInterface;

class MyClass
{
    public function __construct(
        private readonly MailerInterface $mailer
    ) {
    }
}
Copied!

Or where constructor injection is not possible:

$mailer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailerInterface::class);
Copied!

Impact 

This change makes it possible to create your own \My\Custom\Mailer that implements \TYPO3\CMS\Core\Mail\MailerInterface which is used by TYPO3 core. Therefore, it is recommended to use the interface \TYPO3\CMS\Core\Mail\MailerInterface , to let dependency injection inject the desired implementation for every \TYPO3\CMS\Core\Mail\MailerInterface .

Add the following line in Configuration/Services.yaml, to ensure that your custom implementation can be injected.

TYPO3\CMS\Core\Mail\MailerInterface:
  alias: My\Custom\Mailer
Copied!