Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@bztes/strapi-provider-email-gmail-api

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bztes/strapi-provider-email-gmail-api

Strapi email provider for Gmail using googleapi and OAuth 2.0

Source
npmnpm
Version
4.0.1
Version published
Weekly downloads
32
-37.25%
Maintainers
1
Weekly downloads
 
Created
Source

strapi-provider-email-gmail-api

Yet another Strapi email provider for Gmail using OAuth 2.0 ;)

Strapi Versionuse NPM Version
v44.x
v31.x

Installation

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",
  }

Differences in v3

Strapi v3 can't handle scoped provider packages at all. Here the package name must be prefixed with strapi-.

npm i strapi-provider-email-gmail-api@npm:@bztes/strapi-provider-email-gmail-api@1.0.1

package.json:

  "dependencies": {
    "strapi-provider-email-gmail-api": "npm:@bztes/strapi-provider-email-gmail-api@1.0.1",
  }

Preparing Google API

Enable the Gmail API with OAuth authentication in 5 steps

Create a new Project

  • Open the Google Console
  • Create a new Project

Enable Gmail API

  • In the Google Console select 'APIs & Services' -> 'Library'
  • Search for 'Gmail' and click on enable
  • In the Google Console select 'APIs & Services' -> 'OAuth consent screen'
  • Select User Type 'Internal'
  • Provide an App name and email address and click on 'save and continue'
  • Click on 'add or remove scope'
  • Select 'Gmail API .../auth/gmail.send' and click on 'update' and then 'save and continue'

Add Credentials

  • In the Google Console select 'APIs & Services' -> 'Credentials'
  • Select 'create credentials' -> 'OAuth client ID'
  • Select 'Web application' and provide a name
  • For 'Authorized redirect URIs' add 'https://developers.google.com/oauthplayground'
  • Click on 'create'
  • Take the 'Client ID' and 'Client Secret'

Connect a Gmail account

  • Open the Google OAuth 2.0 Playground
  • Click on settings and select 'Use your own OAuth credentials'
  • Enter your 'Client ID' and 'Client Secret' and click on 'close'
  • In Step 1 select 'Gmail API v1' -> '.../gmail.send' and click on 'Authorize APIs'
  • Authorize with your Gmail Account you want to send mails from
  • In Step 2 click on 'Exchange authorization code for tokens'
  • Click on Step 2 and take the 'Refresh Token'

Provider Configuration

VariableTypeDescriptionRequiredDefault
providerstringThe name of this provider 'google'yes
providerOptionsobjectProvider optionsyes
providerOptions.auth.userIdstringThe mail address of the Google account to send e-mails fromyes
providerOptions.auth.clientIdstringOAuth 2.0 Client IDyes
providerOptions.auth.clientSecretstringOAuth 2.0 Client Secretyes
providerOptions.auth.refreshTokenstringOAuth 2.0 Refresh Tokenyes
settingsobjectSettingsyes
settings.defaultFromstringDefault sender mail addressno
settings.defaultReplyTostringThe receiver is asked to reply tono

Provider Configuration Example

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...

Differences in v3

In Strapi v3 all the provider settings are directly enclosed by the email block. The config block must be removed.

module.exports = ({ env }) => ({
  email: {
    provider: 'gmail-api',
    ...
  },
});

Resources

Keywords

strapi

FAQs

Package last updated on 26 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts