Email Workflows / Reacting to new email instantly

Reacting to new email instantly Intermediate

Instead of checking mail on a timer, you can be notified the moment mail arrives: Gmail push notifications or Microsoft Graph change notifications.

What you'll learn

  • Polling vs push
  • How Gmail push works
  • How Outlook notifications work

Before you start

1. Why push?

A routine that checks every 15 minutes can be up to 15 minutes late. Push means the mail service tells your code right away.

2. Gmail: watch + Pub/Sub

  1. Create a Google Cloud Pub/Sub topic (a message channel).
  2. Give Gmail permission to publish to it.
  3. Call Gmail's watch on the mailbox.
  4. Your code receives a notice, then fetches the new messages.
  5. Renew the watch regularly; Google says to call watch at least every 7 days.
Screenshot: Diagram: Gmail to Pub/Sub topic to your bot.

3. Outlook: Graph change notifications

  1. Create a subscription on the user's messages with your webhook URL.
  2. Answer Microsoft's validation request.
  3. Receive notifications, fetch the message, act.
  4. Renew before the subscription expires.

4. Keep it simple

For most people, a routine every 15-30 minutes is plenty. Push is for when minutes matter.

Ideas to try

  • Support desk.
    Explain how I'd get notified instantly when a customer emails support@.
  • Urgent alerts.
    Text me right away when an email from my bank arrives (plan only).
  • Compare.
    Is push worth it for me, or is a 15-minute routine enough?
  • Build.
    Draft code to receive Gmail Pub/Sub notifications on a Cloudflare Worker.

Tips

  • Always fetch the message yourself; notices carry little data.
  • Handle duplicates.
  • Plan for renewals or it silently stops.

Facts about the Grok Bot app come from Cursor's official Grok Bot documentation. Docs: Gmail push, Graph change notifications. Menus and services change; if something looks different, check the official docs or ask your bot.