5.0.0 • Published 2 months ago

@sgsoftware/strapi-plugin-sghp-send-mail v5.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

Strapi Plugin sghp-send-mail

Plugin for Strapi to send emails via REST API.

Requirements

  • Strapi 5

Installation

  1. Install package from npm:

    • Install via npm:

        $ npm install @sgsoftware/strapi-plugin-sghp-send-mail
    • Install via yarn:

        $ yarn add @sgsoftware/strapi-plugin-sghp-send-mail
  2. Create the necessary configuration as described below.

The plugin should now be ready.

Configuration

Add plugin config to ./config/plugins.ts (create, if not yet existing):

module.exports = ({ env }) => ({
    ...
    "sghp-send-mail": {
      config: {
        to: <email dest address>,
        subjectPrefix: <email subject prefix>
      },
    },
    ...
});

Additionally, don't forget to set the right permissions for the REST API using the admin interface.

The plugin will send emails using strapis builtin email plugin, which in turn sends emails through the selected provider (sendmail, by default).

The following example configuration uses nodemailer as a provider in production and email-mock as a mockup that simply prints emails to the log during development:

module.exports = ({ env }) => ({
    ...
    "email": env( "SMTP_HOST" ) ? {
      config: {
        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: {}
      }
    }
    : {
      config: {
        provider: 'strapi-provider-email-mock',
        providerOptions: {},
        settings: {
          // If set to false, each email sent will be logged to console
          quiet: false,
        }
      }
    },
    ...
});

In your env file for development, if SMTP_HOST is not set, the mockup provider will be chosen.

Query from Frontend

Example Query using curl:

$ curl -X POST 'http://localhost:1337/api/sghp-send-mail/send' -H "Content-Type: application/json" -d '{ "from": "someguy@example.com", "subject": "some topic", "message": "hello world" }'

Contribution

Comments, bug reports and pull requests welcome.

5.0.0

2 months ago