37

I have been looking around for how to create a webhook that is triggered when an email is sent or received in Gmail. For example someone sends an email, that email gets POSTed as a JSON object to one of my applications. I have found many middleman applications/services that do this (I found a tool that offers all the functionality I want, but it costs money), but I can't find any documentation on how to actually do this myself so I don't need to pay for it.

Is this possible?

Workman
  • 1,196
  • 1
  • 16
  • 28
Ryan-Neal Mes
  • 6,003
  • 7
  • 52
  • 77
  • 1
    Do you need a pre-send hook or a post-send hook? – rds Aug 21 '14 at 20:54
  • 25
    The close reason here seems clearly invalid. The asker is *explicitly* asking for a way to do this *without* a middleman service; how can that possibly be construed as a tool recommendation question? – Mark Amery Dec 11 '17 at 12:33
  • 1
    I solved it with zapier - this article covers it well: https://zapier.com/help/autoforwarding-email-gmail/ – knagode May 17 '18 at 09:43
  • @knagode I am using Gmail trigger and action is webhook in zapier. May I know if there is any way to read the response from the webhook in gmail-webhook zap , I need to trigger another action based on that response? (i.e gmail - webhook - gmail ) – Pushpa Nov 16 '20 at 10:10
  • @MarkAmery Valid point. I've reframed the question to remove specific tool references and petitioning to reopen. – Workman Apr 26 '23 at 18:38

3 Answers3

12

After some research the best solution I could find was to use the gmail API

To achieve the functionality that zapier offers you would have to have a service or something polling google and querying the status of a users in box. There are also a couple of ways to trigger calls to code, but I do not think this is what zapier does. Check the gmail API for more information.

Ryan-Neal Mes
  • 6,003
  • 7
  • 52
  • 77
5

You can try using context.io They allow you to connect multiple gmail (and others) mailboxes and then create webhooks for different actions. They handle the polling for you and then whenever the condition is met, they call the URL that you provide.

oarevalo
  • 3,298
  • 1
  • 22
  • 19
  • can context.io reply to a threaded email? – itsazzad Jul 29 '15 at 09:16
  • 1
    @SazzadTusharKhan i don't think you can "send" replies via context.io; but you can configure a context.io webhook to "watch" any activity for a specific thread. For gmail, you get better results if you configure your webhook using the gmail's thread id and using the format: "gm-THREAD_ID" – oarevalo Jul 29 '15 at 16:13
  • 6
    2019 update: context.io is officially shutting down due to changes in Google privacy policy – porkbrain Feb 12 '19 at 13:19
  • 1
    context.io deprecation notice: https://blog.context.io/context-io-deprecation-notice-ce8b77e6e477 – hashlash Jun 02 '22 at 01:56
0

If using specifically Gmail doesn't matter to you you can use external services. For example, you can use ProxiedMail - generate a unique proxy email there and set up a webhook URL to your web page where you want to handle it.

It will redirect the letter to Gmail in the end but also will send you a callback to your endpoint. So, the difference here is only domain. Otherwise, you'll need to maintain a connection to Gmail by yourself.