Yet another Strapi email provider for Gmail using OAuth 2.0 ;)
It's required to install this package with a different alias so that it belongs to the @strapi scope.
# npm
npm i @strapi/provider-email-gmail-api@npm:@bztes/strapi-provider-email-gmail-api
# or yarn
yarn add @strapi/provider-email-gmail-api@npm:@bztes/strapi-provider-email-gmail-api
The package.json
should then contain:
"dependencies": {
"@strapi/provider-email-gmail-api": "npm:@bztes/strapi-provider-email-gmail-api@^4.0.0",
}
Enable the Gmail API with OAuth authentication in 5 steps
Variable | Type | Description | Required | Default |
---|---|---|---|---|
provider | string | The name of this provider 'google' | yes | |
providerOptions | object | Provider options | yes | |
providerOptions.auth.userId | string | The mail address of the Google account to send e-mails from | yes | |
providerOptions.auth.clientId | string | OAuth 2.0 Client ID | yes | |
providerOptions.auth.clientSecret | string | OAuth 2.0 Client Secret | yes | |
providerOptions.auth.refreshToken | string | OAuth 2.0 Refresh Token | yes | |
settings | object | Settings | yes | |
settings.defaultFrom | string | Default sender mail address | no | |
settings.defaultReplyTo | string | The receiver is asked to reply to | no |
config/plugins.js
module.exports = ({ env }) => ({
email: {
config: {
provider: 'gmail-api',
providerOptions: {
auth: {
userId: env('EMAIL_OAUTH2_USERID'),
clientId: env('EMAIL_OAUTH2_CLIENTID'),
clientSecret: env('EMAIL_OAUTH2_CLIENTSECRET'),
refreshToken: env('EMAIL_OAUTH2_REFRESHTOKEN'),
},
},
settings: {
defaultFrom: env('EMAIL_FROM'),
defaultReplyTo: env('EMAIL_REPLYTO'),
testAddress: env('EMAIL_TEST_ADDRESS'),
},
},
},
});
.env
EMAIL_FROM=Example Inc. <foo@my-domain.com>
EMAIL_REPLYTO=Example Inc. <foo@my-domain.com>
EMAIL_TEST_ADDRESS=foo@my-domain.com
EMAIL_OAUTH2_USERID=foo@my-domain.com
EMAIL_OAUTH2_CLIENTID=123....321.apps.googleusercontent.com
EMAIL_OAUTH2_CLIENTSECRET=ABC123...
EMAIL_OAUTH2_REFRESHTOKEN=1//123XYZ...