1.1.0 • Published 3 years ago

netlify-plugin-gmail v1.1.0

Weekly downloads
45
License
MIT
Repository
github
Last release
3 years ago

netlify-plugin-gmail 📨

A Netlify Build Plugin for Gmail

This build plugin provides an alternative to Netlify's native e-mail notification offering by sending e-mail from a Gmail account on every Netlify successful or failed build.

File-based installation

  1. Create a netlify.toml in the root of your project. Your file should include the plugins section below:

    [[plugins]]
    package = "netlify-plugin-gmail"
  2. From your project's base directory, use npm, yarn, or any other Node.js package manager to add this plugin to devDependencies in package.json.

    # use npm
    npm install -D netlify-plugin-gmail
    
    # or yarn
    yarn add -D netlify-plugin-gmail

Configuration

You need to configure this plugin using build environment variables and configure your Gmail account. Plugin is using Oauth2 authentication.

  1. First, let’s set up an OAuth Client ID for your app.
  2. Go to Google Cloud APIs and create a new project.
  3. Search for “APIs & Services”
  4. Click on “Credentials” > Click “+ Create credentials” > “OAuth client ID” Type: Web Application Name: “Enter Your Name of Client” Authorized redirect URIs: https://developers.google.com/oauthplayground
  5. Copy both the Client ID and Client Secret.
  6. Go to Oauth Playground > Click on Setting icon on the right > Enable Use your own Oauth credentials > Enter Oauth Client ID & Oatuh Client Secret that you get from the above step > Close
  7. In Select & Authorize APIs, Type https://mail.google.com > Authorize APIs > Login with the account that you want to send from.
  8. Click Exchange authorization code for tokens > Copy Refresh Token.
  9. Set following build environment variables:
GMAIL_SENDER_EMAIL="joedoe@email.com"
GMAIL_RECEIVER_EMAIL="jonhndoe@email.com" # comma separated list of recipients email addresses
GMAIL_AUTH_TYPE="oauth2" # optional - oauth2 is set by default
GMAIL_CLIENT_ID="12354613-blablablabla.apps.googleusercontent.com" # example value
GMAIL_CLIENT_SECRET="q_af1461fafa49faefvv3" # example value
GMAIL_REFRESH_TOKEN="8//423789fafafavaae-jkflamflaga6464848684_faf13fa16f4a984" # example value
OAUTH_PLAYGROUND = "https://developers.google.com/oauthplayground" # optional - this url is set by default

All environment variables

VariableStateExampleDefault value
GMAIL_SENDER_EMAILRequiredjonhndoe@email.com
GMAIL_RECEIVER_EMAILRequiredjoedoe@email.com, johndoe@email.com
GMAIL_CLIENT_IDRequired12354613-blablablabla.apps.googleusercontent.com
GMAIL_CLIENT_SECRETRequiredq_af1461fafa49faefvv3
GMAIL_REFRESH_TOKENRequired
OAUTH_PLAYGROUNDOptionalhttps://developers.google.com/oauthplaygroundhttps://developers.google.com/oauthplayground
GMAIL_AUTH_TYPEOptionaloauth2 or loginoauth2
ON_SUCCESS_BODY_FILEPATHOptional/templates/success-message.ejs${__dirname}/templates/onSuccess.ejs
ON_SUCCESS_SUBJECTOptional[NETLIFY] Build successfull 🎉NETLIFY Build successfull 🎉
ON_ERROR_BODY_FILEPATHOptional/templates/error-message.ejs${__dirname}/templates/onError.ejs
ON_ERROR_SUBJECTOptional[NETLIFY] Build unsuccessfull ❌NETLIFY Build unsuccessfull ❌

Custom email subject and body

You can customize your email subject and body.

To change subject, set either ON_SUCCESS_SUBJECT or ON_ERROR_SUBJECT environment variable.

ON_SUCCESS_SUBJECT="My custom subject for successfull build"
ON_ERROR_SUBJECT="My custom subject for failed build"

To change email body, set either ON_SUCCESS_BODY_FILEPATH or ON_ERROR_BODY_FILEPATH environment variable to point to your *.ejs template file.

ON_ERROR_BODY_FILEPATH=`/templates/success-message.ejs`

Create file /templates/success-message.ejs and put there your custom content:

<h1>Netlify build for site <%= SITE_NAME %> has been sucesfull.</h1>
<p>
  Finished processing build request. Site <%= SITE_NAME %> is live ✨.
  <br />
  URL: <%= URL %> <br />
  DEPLOY_URL: <%= DEPLOY_URL %>
</p>

You can use following variables:

  • <%= URL %>
  • <%= DEPLOY_URL %>
  • <%= SITE_NAME %>
  • <%= SITE_ID %>
  • <%= DEPLOY_ID %>
1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago