Sending Mail
With a working transport, you can call it anywhere you have access to payload by calling payload.sendEmail(message). The message will contain the to, subject and email or text for the email being sent. To see all available message configuration options, see NodeMailer.
Mock transport
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.
payload.init({
email: {
fromName: 'Admin',
fromAddress: 'admin@example.com',
logMockCredentials: true, // Optional
},
// ...
})
Console output when starting payload with a mock email instance and logMockCredentials: true
[06:37:21] INFO (payload): Starting Payload... [06:37:22] INFO (payload): Payload Demo Initialized [06:37:22] INFO (payload): listening on 3000... [06:37:22] INFO (payload): Connected to MongoDB server successfully! [06:37:23] INFO (payload): E-mail configured with mock configuration [06:37:23] INFO (payload): Log into mock email provider at https://ethereal.email [06:37:23] INFO (payload): Mock email account username: hhav5jw7doo4euev@ethereal.email [06:37:23] INFO (payload): Mock email account password: VNdGcvDZeyEhtuPBqf
The mock email handler is used when the payload is started with neither transport nor transportOptions to know how to deliver email.
Using multiple mail providers
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.