Mailer Component

Description

Added in [Symfony 4.3](Symfony 4.3). Out of the box the following services are supported:

  • Amazon SES
  • MailChimp
  • Mailgun
  • Gmail
  • Postmark
  • SendGrid

Services need to be installed seperately:

composer require symfony/amazon-mailer

And environment variables need to be configured:

AWS_ACCESS_KEY=…
AWS_SECRET_KEY=…
MAILER_DSN=smtp://AWS_SECRET_KEY@ses

Syntax

use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;

class SomeService
{
private $mailer;

public function __construct(MailerInterface $mailer)
{
    $this->mailer = $mailer;
}

public function sendNotification()
{
    $email = (new Email())
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Time for Symfony Mailer!')
        ->text('Sending emails is fun again!')
        ->html('<p>See Twig integration for better HTML integration!</p>');

    $this->mailer->send($email);
}

}

Signing Messages

It’s also possible to [Signing and Encrypting Messages](Signing and Encrypting Messages) messages.

DKIM email authentication

  • DKIM[fn:dkim] authentication is [DKIM Email Authentication](DKIM Email Authentication) as well.

Footnotes

[fn:dkim]https://en.wikipedia.org/wiki/DomainKeys\_Identified\_Mail