The mail plugin

So let's start by creating our Mail plugin class, and if you remember, plugins go inside the Plugin folder of our module namespace. Mail plugins belong inside a Mail folder. So this is what a simple skeleton mail plugin class can look like:

namespace Drupal\hello_world\Plugin\Mail;use Drupal\Core\Mail\MailFormatHelper;use Drupal\Core\Mail\MailInterface;use Drupal\Core\Plugin\ContainerFactoryPluginInterface;use Symfony\Component\DependencyInjection\ContainerInterface;/** * Defines the Hello World mail backend. * * @Mail( *   id = "hello_world_mail", *   label = @Translation("Hello World mailer"), *   description = @Translation("Sends an email using an external API specific to our Hello World module.") * ) */class HelloWorldMail implements ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.