Gmail Push Notifications in Google Apps Script

Spencer Easton · 18K views · 2016 · 39:04

Open on YouTube

Web developmentCloud, DevOps & reliabilitytutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the go-to walkthrough for wiring Gmail API push notifications and Pub/Sub to an Apps Script webhook.

Recommended by 3 people across 3 different months, 2016 to 2022.

What it is

Spencer Easton walks through a minimal setup for triggering a Google Apps Script web app from Gmail push notifications. He configures the Gmail watch request, Cloud Pub/Sub topic and subscription, and an Apps Script doPost endpoint that logs incoming mail events to a spreadsheet.

What people said

Recommends Nathaniel MacIver · 2017-03 · Stack Overflow · on “Need Help creating GMAIL Pub/Sub Notification service to SpreadsheetApp (Google Appscript)”

I wish I didn't have to repost this question, but my boss pushed this one up to high priority, and I need help to sort this out. I'm trying to use a GAS script to pull pub/sub notifications from an address on my GSuite Domain (currently, I'm testing on mine). Basically, I'm trying to accomplish what is described in all this material: 1)Great Github Project from Spencer Easton [LINK] (Instructional Video) [this video] 2) pubsub API for GMAIL [LINK] 3) Notification Help [LINK] 4) Real-time notifications [LINK] 5)Endpoint documentation [LINK] I have created the GAS project documented in reference 1 on my Work domain in Google Drive, published as draft to chrome store, added PUB/SUB API's and librari

Recommends Prasanth Chinni · 2020-06 · Stack Overflow · on “Google GMail callback when someone reply to thread”

You can use the Push notifications provided by Gmail API. The document is available here: [LINK] It's pretty much straight forward. Create a topic, then create a push subscription for the topic. It requires a webhook pointing to your web app. Grant necessary permission to the Gmail service account as mentioned in the document. Use the below Python code to get notified: request = { 'labelIds': ['INBOX'], 'topicName': 'projects/myproject/topics/mytopic' } gmail.users().watch(userId='me', body=request).execute() We get a response with HistoryId. Tracking all the messages since the HistoryId can be done like this: history = (service.users().history().list(userId=user_id, startHistoryId=start_his

Recommends TheAddonDepot · 2021-06 · Stack Overflow · on “Gmail apps script: Execute a function upon reply”

You can achieve this using Gmail API Push Notifications, Cloud Pubsub API and a GAS Web App as an HTTP endpoint/Webhook (as of late 2020, Cloud Pubsub no longer requires domain verification for Http endpoints so GAS WebApps are once again a viable option). The following resources should be enough to get you started: Gmail API Push Notification Guide [LINK] Reference Documentation [LINK] Spencer Easton's Youtube tutorial [this video] (some parts of the tutorial are no longer relevant since domain verification is not necessary anymore but its a good jumping off point to start learning about the process) Cloud Pubsub API Documentation [LINK] [LINK] GAS WebApp Documentation/Guide [LINK]

Cites Arun D · 2016-09 · Stack Overflow · on “Gmail watch using Google Apps Script and Push Notification”

I am creating an app to add watch for the app user's gmail account using Google Apps Script. For testing the working of watch, I have used the following app script code which I got from a youtube tutorial by Spencer Easton ( [this video] ) function doPost(e) { var message = JSON.parse(e.postData.getDataAsString()).message; var data = Utilities.newBlob(Utilities.base64Decode(message.data)).getDataAsString(); var ss = SpreadsheetApp.openById('my_google_sheet_id').getSheets()[0]; ss.appendRow([new Date(), message.message_id, data, "newMail"]); return 200; } function enrollEmail() { var watchRes = Gmail.newWatchRequest(); watchRes.labelIds = ["INBOX"]; watchRes.labelFilterAction = "include"; watchRes

Cites mrpepo877 · 2019-05 · Stack Overflow · on “Invalid topicName does not match”

I have been trying to solve this problem all the day but I can't find where the error. I am making a program to detect when I receive an mail in my gmail and write that mail in a Google Spreadsheet, I am using the Gmail API and Google Apps Script. This is my code: gs code is : function doPost(e) { var message = JSON.parse(e.postData.getDataAsString()).message var data = Utilities.newBlob(Utilies.base64Decode(message.data)).getDataAsString()[0]; var ss = SpreadsheetApp.openById('1b8s5PLItCsmk8l1q0T1KHYOzjW7iDv4sRXSFvAxVFbQ').getSheets()[0]; ss.appendRow([new Date(), message.message_id,data]); return 200; } function capturemail(){ var WatchRes = Gmail.newWatchRequest(); WatchRes.labelIds = ["I

Cites cmbuckley · 2022-02 · Stack Overflow · on “Gmail watch using Google Apps Script and Push Notification”

This peculiarity is mentioned in the video OP linked [this video] - this was required for the webhook to be acknowledged.