NodemailerMade by Strapi
Nodemailer provider for Strapi
@strapi/provider-email-nodemailer
Resources
Links
Installation
# using yarn
yarn add @strapi/provider-email-nodemailer
# using npm
npm install @strapi/provider-email-nodemailer --save
Example
Path - config/plugins.js
1module.exports = ({ env }) => ({
2 // ...
3 email: {
4 config: {
5 provider: 'nodemailer',
6 providerOptions: {
7 host: env('SMTP_HOST', 'smtp.example.com'),
8 port: env('SMTP_PORT', 587),
9 auth: {
10 user: env('SMTP_USERNAME'),
11 pass: env('SMTP_PASSWORD'),
12 },
13 // ... any custom nodemailer options
14 },
15 settings: {
16 defaultFrom: 'hello@example.com',
17 defaultReplyTo: 'hello@example.com',
18 },
19 },
20 },
21 // ...
22});
Check out the available options for nodemailer: https://nodemailer.com/about/
Development mode
You can override the default configurations for specific environments. E.g. for
NODE_ENV=development
in config/env/development/plugins.js:
1module.exports = ({ env }) => ({
2 email: {
3 config: {
4 provider: 'nodemailer',
5 providerOptions: {
6 host: 'localhost',
7 port: 1025,
8 ignoreTLS: true,
9 },
10 },
11 },
12});
The above setting is useful for local development with maildev.
Custom authentication mechanisms
It is also possible to use custom authentication methods. Here is an example for a NTLM authentication:
1const nodemailerNTLMAuth = require('nodemailer-ntlm-auth');
2
3module.exports = ({ env }) => ({
4 email: {
5 config: {
6 provider: 'nodemailer',
7 providerOptions: {
8 host: env('SMTP_HOST', 'smtp.example.com'),
9 port: env('SMTP_PORT', 587),
10 auth: {
11 type: 'custom',
12 method: 'NTLM',
13 user: env('SMTP_USERNAME'),
14 pass: env('SMTP_PASSWORD'),
15 },
16 customAuth: {
17 NTLM: nodemailerNTLMAuth,
18 },
19 },
20 settings: {
21 defaultFrom: 'hello@example.com',
22 defaultReplyTo: 'hello@example.com',
23 },
24 },
25 },
26});
Usage
:warning: The Shipper Email (or defaultfrom) may also need to be changed in the
Email Templates
tab on the admin panel for emails to send properly
To send an email from anywhere inside Strapi:
1await strapi.plugin('email').service('email').send({
2 to: 'someone@example.com',
3 from: 'someone2@example.com',
4 subject: 'Hello world',
5 text: 'Hello world',
6 html: `<h4>Hello world</h4>`,
7});
The following fields are supported:
Field | Description |
---|---|
from | Email address of the sender |
to | Comma separated list or an array of recipients |
replyTo | Email address to which replies are sent |
cc | Comma separated list or an array of recipients |
bcc | Comma separated list or an array of recipients |
subject | Subject of the email |
text | Plaintext version of the message |
html | HTML version of the message |
attachments | Array of objects See: https://nodemailer.com/message/attachments/ |
Troubleshooting
Check your firewall to ensure that requests are allowed. If it doesn't work with
1port: 465,
2secure: true
try using
1port: 587,
2secure: false
to test if it works correctly.
Install now
npm install @strapi/provider-email-nodemailer
Create your own plugin
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.