Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger event from gmail new mail

Is there an API or events that can be trapped within gmail so that I can initiate a workflow or even fire a python script.

I am trying to automate a job which will extract a csv attachment from an email that has arrived in gmail. It will then ETL the csv into BigQuery.

Any thoughts ?

like image 830
Vinay Joseph Avatar asked Feb 19 '14 10:02

Vinay Joseph


People also ask

Can you create an event from a Gmail message?

Create an event from a Gmail messageOn your computer, go to Gmail. Open the message. Create event. Google Calendar creates an event, copying the Gmail message title and text.

Does Gmail have push notifications?

On Android devicesOpen the Gmail app. Select your account and scroll to Notifications. Tap Inbox notifications and select your notification settings.


2 Answers

Recently did this integration:

  1. Turn on watching for message events: https://developers.google.com/gmail/api/v1/reference/users/watch

  2. When you get a new incoming messageId (messagesAdded history type) you ask for its information (in full format): https://developers.google.com/gmail/api/v1/reference/users/messages/get

  3. In metadata you look for a payload.parts[i] where it has body.attachmentId and get an attachment using its id: https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get

like image 167
Max Ostapenko Avatar answered Sep 28 '22 01:09

Max Ostapenko


Im not sure within gmail itself,

but one thing you try is to write a python script utilising IMAP lib to read gmail messages and load it to bigquery using googleclient python. Set it using cron to run every x minutes to check the gmail account.

This should give you a starter code to read gmail messages:

https://gist.github.com/baali/2633554

If you want just new messages, just replace the search param 'ALL' with 'UNSEEN'.

More info: https://docs.python.org/2/library/imaplib.html

Example python to load it to BigQuery: https://developers.google.com/bigquery/loading-data-into-bigquery

I am still waiting for IFTTT https://ifttt.com/wtf to provide the API for users to create their own channel or custom action. i.e. Google BigQuery channel.

Hope that helps.

like image 34
Wan Bachtiar Avatar answered Sep 28 '22 00:09

Wan Bachtiar