Payload comes ready to send your application's email. Whether you simply need built-in password reset email to work or you want customers to get an order confirmation email, you're almost there. Payload makes use of NodeMailer for email and won't get in your way for those already familiar.
For email to send from your Payload server, some configuration is required. The settings you provide will be set
Three ways to set it up
transportOptionsand Payload will do the set up for you.
transportobject can be assigned a nodemailer transport object set up in your server scripts and given for Payload to use.
The following options are configurable in the
|The name part of the From field that will be seen on the delivered email|
|The email address part of the From field that will be used when delivering email|
|The NodeMailer transport object for when you want to do it yourself, not needed when transportOptions is set|
|An object that configures the transporter that Payload will create. For all the available options see the NodeMailer documentation or see the examples below|
|If set to true and no transport/transportOptions, ethereal credentials will be logged to console on startup|
* An asterisk denotes that a property is required.
Simple Mail Transfer Protocol, also known as SMTP can be passed in using the
transportOptions object on the
Example email part using SMTP:
Many third party mail providers are available and offer benefits beyond basic SMTP. As an example your payload init could look this if you wanted to use SendGrid.com though the same approach would work for any other NodeMailer transports shown here or provided by another third party.
To take full control of the mail transport you may wish to use
nodemailer.createTransport() on your server and provide it to Payload init.
With a working transport you can call it anywhere you have access to payload by calling
message will contain the
text for the email being sent. To see all available message configuration options see NodeMailer.
By default, Payload uses a mock implementation that only sends mail to the ethereal capture service that will never reach a user's inbox. While in development you may wish to make use of the captured messages which is why the payload output during server output helpfully logs this out on the server console.
To see ethereal credentials, add
logMockCredentials: true to the email options. This will cause them to be logged to console on startup.
Console output when starting payload with a mock email instance and logMockCredentials: true
The mock email handler is used when payload is started with neither
transportOptions to know how to deliver email.
Payload supports the use of a single transporter of email, but there is nothing stopping you from having more. Consider a use case where sending bulk email is handled differently than transactional email and could be done using a hook.