Custom mail plugins

In the preceding section, we saw how we can use the Drupal 8 mail API to send emails programmatically in Drupal 8. In doing so, we used the default PHP mailer, which although is good enough for our example, might not be so for our application. For example, we might want to use an external service via an API.

In this section, we will teach you how to do this. To this end, we will need to write our own mail plugin that does just that, and then simply tell Drupal to use that system instead of the default one. Yet another plugin-based, noninvasive, extension point.

Before we start, I would like to mention that we won't go into any kind of detail related to the potential external API. Instead, we will stop at the Drupal 8-specific ...

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.