strapi-provider-email-gmail-2lo
v3.5.1
Published
Gmail provider with 2-legged OAuth and a service account for the Strapi framework
Downloads
110
Maintainers
Readme
strapi-provider-email-gmail-2lo
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:
- v3.5.x (recommended)
- v3.x
Not having Google Workspace (previously G suite) will not work with this provider.
Installation
# using yarn
yarn add strapi-provider-email-gmail-2lo
# using npm
npm install strapi-provider-email-gmail-2lo --save
Setup
- Enable the Gmail API
- Configure the OAuth consent screen
- Create a service account
- Create a new Private key for your service account
- Configure the provider in
config/plugins
| Variable | Type | Description | Required | Default | | ------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------- | --------- | | provider | string | The name of the provider you use | yes | | | providerOptions | object | Provider options | yes | | | providerOptions.username | string | An existing email address within your domain/project | yes | | | providerOptions.clientId | number | Service account API Client id | yes | | | providerOptions.privateKey| string | Service account private key | yes | | | settings | object | Settings | no | {} | | settings.defaultFrom | string | Default sender mail address, exist in domain | no | undefined | | settings.defaultReplyTo | string | array | Default address or addresses the receiver is asked to reply to | no | undefined |
Enable the scope in G Workspace (required)
The following steps will authorize the right scope, to allow sending email with G Workspace:
- Go to G Workspace admin dashboard > Security > API controls > Manage domain-wide delegation
- Add an authorized client
- Client name:
client_id
- Scopes: https://mail.google.com/
- Authorize
Example
Path - config/plugins.js
module.exports = ({ env }) => ({
// ...
email: {
provider: 'gmail-2lo',
providerOptions: {
username: '[email protected]',
clientId: env('EMAIL_CLIENT_ID'),
privateKey: env('EMAIL_PRIVATE_KEY').replace(/\\n/g, '\n'),
},
settings: {
defaultFrom: '[email protected]',
defaultReplyTo: '[email protected]',
},
},
// ...
});
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"