An updated version of Gmail Push Notifications in Apps Script
This sample project shows how to setup your Apps Script project to register a Gmail account for push notifications and how to programmatically set up the the proper pubsub publishing channels and subscriptions.
- Create a new Apps Script project using the two .gs files in this repo.
- Add the following libraries:
PubSubApp -1BX8k4tkiA3CZGIZ0hHccfiF7o-EvjqLCt3hoU3osDQBhnGlQTRnawOGE
GSApp -1wkfv_Mm0IyruEZyPZsrctcSmc1T9y0-bArl2gIzMd6RVYJAwWeJ5gpDu
- Publish the project as a web app
- Register the web app in the Chrome web store leaving it in draft mode. This will verifiy ownership of the script.
- Run the script from the cuurrent web app URL. (the /exec one). You will get an error about no doGet(). Copy the URL it redirected you toward.
- Add the URL to the
WEBHOOK_URL
var in main.gs - Open up the project developers console:
a) Under Credentials -> Domain Verification: Add the url you copied inWEBHOOK_URL
in step 6 ommiting theexec
from the end
b) Create a new service account. Download the credentials as json.
c) Under Overview: Enable the PubSub API and the Gmail API
d) Copy the json credentials and paste it into script properties under the keyjsonKey
. - Copy the developers console project Id to
PROJECTID
var in main.gs - Create a spreadsheet. Create a sheet called
Log
. Copy the file Id and paste it inSpreadsheetApp.openById()
of doPost(). - Update the webapp version to pick up changes made to the project.
- Run
setupPubSub()
- Run
enrollEmail()
to start listening to your Gmail notifications. They will be logged to the spreadsheet set up in step 9. - Run
disEnrollEmail()
to stop listening to your Gmail notifications.