Webiny Overview > Features
Mailer
Overview of Webiny mailer package.
- How to use api-mailer to send e-mails
- How to use api-mailer with basic configuration
- How to use api-mailer with advanced configuration
About
Starting from 5.30.0 version of Webiny we have a mailer package (@webiny/api-mailer
) via which you can send e-mails.
Available Mailers
We have a couple of built-in e-mail mailers:
- Dummy Mailer - does not send e-mails, just records them in an array which you can access later
- SMTP Mailer - sends e-mails with the help of nodemailer library
Dummy Mailer
A mailer which pretends to be sending e-mails. Used for testing and as a backup in case no other mailer is configured or defined.
You can manually set it as the mailer so e-mails never actually get sent:
SMTP Mailer
A mailer which sends e-mails via the defined SMTP credentials. In the background it uses nodemailer library to send the e-mails.
Basic Configuration
The configuration is done via the environment variables:
If any of these variables is not defined, mailer will default to the Dummy Mailer.
Advanced Configuration
The advanced configuration is done by creating your own SMTP mailer with custom config. You can use our createSmtpMailer
method, you just need to pass the custom configuration.
Here is an example on how to configure custom mailer:
Note that setMailer
method supports both setting the variable of Mailer
type or an async Mailer
factory.
Here is an example of a context plugin which sets mailer via factory:
Usage
For example, let’s say you want to send an e-mail when user creates an entry in the Person
model.
You would want to subscribe to the onAfterEntryCreate
event and send an e-mail only when added entry to that certain model.