Search code examples
google-apps-scriptgmail

“Pushing” Gmail to GAS — using Gmail forwarding to trigger GAS script


Summary

Is it possible to use the Gmail forwarding feature to send (i.e., “push”) via HTTP (GET/POST) to my GAS script URL? (And perhaps include its contents as a parameter?)

Goal/Background

My goal is to immediately process my incoming Gmail instead of, say, using the GAS trigger feature to query and “pull” my Gmail on a periodic basis.

The former method is relatively immediate. Whereas, the latter method creates an expected delay equal to the mean interval time between (automatically triggered) queries to my inbox.

Possible Solutions

1. Gmail Data API

This documentation states Gmail lacks a data API.

2. Atom/RSS Feeds

Atom/RSS feeds still require an aggregator to pull the data from the server and, thus, do not accomplish my goal of a push-only solution to my GAS URL to, then, in turn, trigger my script via doGet() or doPost().

3. IMAP/POP

These solutions are designed for desktop/offline processing of emails and, therefore, do not meet my goals. I need a solution that lives on the web and automates my web-based email checking tasks.

4. High-frequency GAS Trigger

A, say, 60-second trigger interval in GAS does not work because there is a cost to such high-frequency triggers in GAS due to quota limitations. i.e., I don't want to use up that much quota space on this one task because I need it for other stuff.

5. 3rd Party Listeners

I would prefer something free if possible. Someone has suggested Zapier® — which does have a free version. Do these work? Are there others?

Conclusion

Are there any creative ideas out there? Perhaps to point me in a creative direction?

I would even settle for just a way to be immediately notified (programmatically) that I received a new email.


Solution

  • A trigger can kick off a script every 60 seconds. As you stated before, this puts your average notification at 30 seconds (let's not get started on possible flaws in statistical assumptions).

    Another possibility for a more immediate action is to use a service like Zapier.com as a listener. It can listen for new emails in your gmail inbox, apply filters, and initiate a GET/POST to the URL for your Apps Script (make sure it is the newest version published).

    I hope this helps. Curious why you need immediate handling of the messages ...