Description

Added in 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_ACCESS_KEY:$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 sign and encrypt messages.

DKIM email authentication

Footnotes

Footnotes

  1. https://en.wikipedia.org/wiki/DomainKeys_Identified_Mail