3.14.2 • Published 3 months ago

@akemona-org/strapi-provider-email-nodemailer v3.14.2

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 months ago

strapi-provider-email-nodemailer

Maintenance release by Akemona

Resources

Links

Prerequisites

You need to have the plugin strapi-plugin-email installed in your Strapi project.

Installation

# using yarn
yarn add strapi-provider-email-nodemailer

# using npm
npm install strapi-provider-email-nodemailer --save

Example

Path - config/plugins.js

module.exports = ({ env }) => ({
  email: {
    provider: 'nodemailer',
    providerOptions: {
      host: env('SMTP_HOST', 'smtp.example.com'),
      port: env('SMTP_PORT', 587),
      auth: {
        user: env('SMTP_USERNAME'),
        pass: env('SMTP_PASSWORD'),
      },
      // ... any custom nodemailer options
    },
    settings: {
      defaultFrom: 'hello@example.com',
      defaultReplyTo: 'hello@example.com',
    },
  },
});

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:

module.exports = ({ env }) => ({
  email: {
    provider: 'nodemailer',
    providerOptions: {
      host: 'localhost',
      port: 1025,
      ignoreTLS: true,
    },
  },
});

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:

const nodemailerNTLMAuth = require('nodemailer-ntlm-auth');

module.exports = ({ env }) => ({
  email: {
    provider: 'nodemailer',
    providerOptions: {
      host: env('SMTP_HOST', 'smtp.example.com'),
      port: env('SMTP_PORT', 587),
      auth: {
        type: 'custom',
        method: 'NTLM',
        user: env('SMTP_USERNAME'),
        pass: env('SMTP_PASSWORD'),
      },
      customAuth: {
        NTLM: nodemailerNTLMAuth,
      },
    },
    settings: {
      defaultFrom: 'hello@example.com',
      defaultReplyTo: 'hello@example.com',
    },
  },
});

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:

await strapi.plugins['email'].services.email.send({
  to: 'someone@example.com',
  from: 'someone2@example.com',
  subject: 'Hello world',
  text: 'Hello world',
  html: `<h4>Hello world</h4>`,
});

The following fields are supported:

FieldDescription
fromEmail address of the sender
toComma separated list or an array of recipients
replyToEmail address to which replies are sent
ccComma separated list or an array of recipients
bccComma separated list or an array of recipients
subjectSubject of the email
textPlaintext version of the message
htmlHTML version of the message
attachmentsArray of objects See: https://nodemailer.com/message/attachments/

Troubleshooting

Check your firewall to ensure that requests are allowed. If it doesn't work with

port: 465,
secure: true

try using

port: 587,
secure: false

to test if it works correctly.

3.14.2

3 months ago

3.14.1

3 months ago

3.14.0

3 months ago

3.13.2

3 months ago

3.13.1

3 months ago

3.13.0

3 months ago

3.12.3

1 year ago

3.12.4

1 year ago

3.12.2

1 year ago

3.12.1

1 year ago

3.12.0

1 year ago

3.11.0

1 year ago

3.10.4

1 year ago

3.10.3

1 year ago

3.10.2

1 year ago

3.10.1

1 year ago

3.10.0

1 year ago

3.9.4

1 year ago

3.9.3

1 year ago

3.9.3-next.1

1 year ago

3.9.2

1 year ago

3.9.1

1 year ago

3.9.0

1 year ago

3.8.2

1 year ago

3.8.1

1 year ago

3.8.0

1 year ago

3.7.7-next.3

1 year ago

3.7.7-next.2

1 year ago

3.7.7-next.1

1 year ago

3.7.6

1 year ago

3.7.5

1 year ago

3.7.4

1 year ago

3.7.2

1 year ago

3.7.1

1 year ago

3.7.0

1 year ago