4.0.2 • Published 2 years ago

@zmiori/strapi-provider-email-gmail-2lo-v4 v4.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

strapi-provider-email-gmail-2lo-v4

Strapi v4 version of the strapi-provider-email-gmail-2lo package.

This package is an email provider for the headless CMS Strapi. You can use this provider to send mail programmatically with @strapi/plugin-email.

This provider enables you to send email with the Gmail API using a 2-legged OAuth configuration, when using G Workspace.

Supported versions:

  • v4.x.x

Not having Google Workspace (previously G suite) will not work with this provider.

Installation

It's required to install this package with a different alias so that it belongs to the @strapi scope.

# using yarn
# npm
npm i @strapi/provider-email-gmail-2lo-v4@npm:@zmiori/strapi-provider-email-gmail-2lo-v4

# or yarn
yarn add @strapi/provider-email-gmail-2lo-v4@npm:@zmiori/strapi-provider-email-gmail-2lo-v4

The package.json should then contain:

  "dependencies": {
    "@strapi/provider-email-gmail-2lo-v4": "npm:@zmiori/strapi-provider-email-gmail-2lo-v4@^4.0.0",
  }

Setup

1) Enable the Gmail API 2) Configure the OAuth consent screen 3) Create a service account 4) Create a new Private key for your service account 5) Configure the provider in config/plugins

VariableTypeDescriptionRequiredDefault
providerstringThe name of the provider you useyes
providerOptionsobjectProvider optionsyes
providerOptions.usernamestringAn existing email address within your domain/projectyes
providerOptions.clientIdnumberService account API Client idyes
providerOptions.privateKeystringService account private keyyes
settingsobjectSettingsno{}
settings.defaultFromstringDefault sender mail address, exist in domainnoundefined
settings.defaultReplyTostring | arrayDefault address or addresses the receiver is asked to reply tonoundefined

Enable the scope in G Workspace (required)

The following steps will authorize the right scope, to allow sending email with G Workspace: 1) Go to G Workspace admin dashboard > Security > API controls > Manage domain-wide delegation 2) Add an authorized client

Example

Path - config/plugins.js

module.exports = ({ env }) => ({
  // ...
  email: {
    config: {
      provider: 'gmail-2lo-v4',
    providerOptions: {
      username: 'myemail@example.com',
      clientId: env('EMAIL_CLIENT_ID'),
      privateKey: env('EMAIL_PRIVATE_KEY').replace(/\\n/g, '\n'),
    },
    settings: {
      defaultFrom: 'myemail@example.com',
      defaultReplyTo: 'myemail@example.com',
    },
    }
  },
  // ...
});

TIP: When using environment variables for your privateKey, as in the example above, include all the \n in you .env file, like so:

EMAIL_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nAbC...xYz\n-----END PRIVATE KEY-----\n"

Resources

Links