function SymfonyMailer::getMailer

Same name in other branches
  1. 10 core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php \Drupal\Core\Mail\Plugin\Mail\SymfonyMailer::getMailer()

Returns a minimalistic Symfony mailer service.

1 call to SymfonyMailer::getMailer()
SymfonyMailer::mail in core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().

File

core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php, line 154

Class

SymfonyMailer
Defines an experimental mail backend, based on the Symfony mailer component.

Namespace

Drupal\Core\Mail\Plugin\Mail

Code

protected function getMailer() : MailerInterface {
    if (!isset($this->mailer)) {
        $dsn = \Drupal::config('system.mail')->get('mailer_dsn');
        $dsnObject = new Dsn(...$dsn);
        // Symfony Mailer and Transport classes both optionally depend on the
        // event dispatcher. When provided, a MessageEvent is fired whenever an
        // email is prepared before sending.
        //
        // The MessageEvent will likely play an important role in an upcoming mail
        // API. However, emails handled by this plugin already were processed by
        // hook_mail and hook_mail_alter. Firing the MessageEvent would leak those
        // mails into the code path (i.e., event subscribers) of the new API.
        // Therefore, this plugin deliberately refrains from injecting the event
        // dispatcher.
        $factories = Transport::getDefaultFactories(logger: $this->logger);
        $transportFactory = new Transport($factories);
        $transport = $transportFactory->fromDsnObject($dsnObject);
        $this->mailer = new Mailer($transport);
    }
    return $this->mailer;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.