The alternative to polling Gmail over IMAP is push. For an agent or support bot that reads a Gmail mailbox, call the Gmail API's users.watch so Gmail publishes a Cloud Pub/Sub notification when the mailbox changes, then read the new messages with history.list. The watch has to be renewed at least every 7 days (Google recommends daily). For Outlook, Microsoft Graph change notifications do the same, with subscriptions that last under 7 days. If the bot doesn't need a person's existing mailbox, skip the sync entirely: give it its own address on an inbound email API that posts every message to your webhook (Postmark, Mailgun, SendGrid, Resend, AgentMail or Bavimail).
We build Bavimail. Facts about Google, Microsoft and the other providers come from their own documentation, checked on December 3, 2026.
Why is polling Gmail over IMAP a problem for an agent?
- Polling is slow on purpose. If an account makes too many requests, Google suspends it, "typically" for an hour and up to 24 hours, and recommends checking for new mail "once every 15 minutes" (server request limits). A support bot that answers 15 minutes late is not much of a bot.
- Connections don't last. Gmail IMAP sessions last up to about 24 hours, and about an hour when authenticated with OAuth, the usual access token lifetime (IMAP, POP and SMTP).
- Passwords are gone. Since May 1, 2025, Google Workspace accounts no longer accept apps that sign in with a username and password; "you must use OAuth" (IMAP setup).
- There are daily caps. IMAP downloads are capped at 2,500 MB a day per account (bandwidth limits), and Gmail can be added to up to 15 email clients at a time (Gmail Help).
IMAP IDLE removes the polling delay but not the connection work. RFC 2177 lets the server push changes to the mailbox the connection has selected, and advises clients to "re-issue it at least every 29 minutes." You still keep one live connection per watched mailbox, plus reconnect and resync logic.
How do Gmail push notifications with Pub/Sub work?
From Google's push notifications guide:
- Create a Pub/Sub topic and a push or pull subscription.
- Grant
[email protected]permission to publish to the topic. - Call
users.watchwith thetopicName, optionally limited to labels such asINBOX. The response returns ahistoryIdand anexpiration. - Each notification decodes to
{"emailAddress": "...", "historyId": "..."}and nothing else. Callhistory.listfrom your last savedhistoryIdto see what arrived, then fetch the messages. - Call
watchagain beforeexpiration(users.watch): at least every 7 days, daily by Google's recommendation.
What to plan for:
- One event per second per user. Notifications above that rate are dropped.
- Missed notifications happen. Google says that "in rare situations, notifications might be delayed or dropped," and recommends calling
history.listperiodically as a fallback. - Old history IDs expire. A
historyIdis "typically valid for at least a week, but in some rare circumstances may be valid for only a few hours"; an expired one returns HTTP 404 and you must do a full sync (history.list). - Quota.
watchcosts 100 units,history.list2, andmessages.get20 (60 for the full or raw format), against 6,000 units per user per minute (Gmail API quotas). - Agents calling the API directly. Google's Workspace API pricing page says that starting February 1, 2027, "external AI agents calling Google Workspace REST APIs directly are limited to Standard Tier quotas."
Replies the bot sends from that mailbox still count against Gmail's sending limits: 2,000 messages a day for a Workspace user (sending limits).
What about Outlook and Microsoft 365?
Microsoft Graph change notifications post to your webhook when a message is created, updated or deleted. Subscribe to /users/{id}/messages or a folder such as the inbox, with Mail.ReadBasic or Mail.Read. From the subscription and latency tables:
- A message subscription lasts at most 10,080 minutes (under seven days), or 1,440 minutes when notifications include the encrypted message data. Renew before it expires.
- Average latency is under 1 minute, at most 3 minutes.
- A mailbox allows 1,000 active subscriptions across all apps.
- Microsoft recommends lifecycle notifications so your app can detect removed subscriptions or missed notifications and recover.
Which inbound email webhooks can replace IMAP polling?
When the bot can have its own address ([email protected], say), point that domain's MX record at a provider and let it post each message to you. Nothing to sync, renew or reconnect.
| Service | What arrives at your endpoint | If your endpoint fails |
|---|---|---|
| Postmark | The parsed message as JSON, attachments inline, plus StrippedTextReply | 10 retries from 1 minute up to 6 hours apart; a 403 stops them |
| Mailgun | A route's forward() POST, form-encoded or JSON | Retries for about 8 hours (10 min to 4 h apart); a 406 stops them |
| SendGrid Inbound Parse | multipart/form-data, or the raw MIME message | Not stated on the setup page |
| Resend Receiving | Metadata only; fetch body and attachments by API | 8 attempts over about 27 hours (retries) |
| AgentMail | message.received with the body inline up to 64 KiB, else a link valid 1 hour; WebSockets also available | 8 attempts over about 27.5 hours |
| Bavimail | Signed email.inbound.received summary with a 100-character preview; full message by API | 6 attempts over about 4 minutes; then catch up with GET /inbound-emails |
Gmail push or an inbound webhook: which should a support bot use?
| Gmail push (or Graph) | Inbound webhook on the bot's own address | |
|---|---|---|
| Address | The existing mailbox, history included | A new address, or a subdomain you point at the provider |
| Setup | Google Cloud project, OAuth consent, Pub/Sub topic | MX and authentication records on the domain |
| Ongoing work | Renew the watch, sync from historyId, handle 404 full syncs | Verify signatures, deduplicate events, catch up after outages |
| Sending | The mailbox's Gmail limits | The provider's plan |
Choose Gmail push when the bot must work inside a person's or a team's existing Gmail mailbox. Choose an inbound webhook when the bot can own its address.
Where Bavimail fits, and where it doesn't
Bavimail is an inbound webhook on addresses at a domain you verify:
- Stored first, then notified. Each message is parsed and stored before the
email.inbound.receivedwebhook goes out. The event is signed with HMAC-SHA256 over the timestamp and raw body, and carries a summary with a 100-characterbody_preview(inbound, webhooks). - Nothing to resync. Messages stay readable until you delete their thread, so a catch-up job pages through
GET /inbound-emails(newest first, up to 100 per page) and processes ids it hasn't seen.GET /inbound-emails/{email_id}returns bodies, headers, SPF/DKIM/DMARC verdicts and attachments as signed download links. - Replies stay threaded with
thread_idandin_reply_toonPOST /outbound-emails(threading). - One API key for sending, inbound, inboxes, domains and webhooks, and a hosted MCP server at
https://mcp.bavimail.com/(OAuth, 92 tools). - Price: Developer is $5 a month for 50,000 emails, 10 domains with 10 inboxes each (pricing).
Where it doesn't fit:
- It gives the bot its own inboxes; it isn't, today, a way to read an existing Gmail or Outlook mailbox. For that, use Gmail push, Microsoft Graph or Nylas.
- The retry window is short. Six attempts span about 4 minutes, and a timeout or connection error is held instead of resent, so run the catch-up job (what happens when your webhook is down).
- No quoted-reply stripping.
body_textincludes whatever history the sender quoted; Postmark'sStrippedTextReplydoes this for you. - No prompt-injection screening of inbound mail, and no inbox on Free, which has no custom domain.
To build the handler, follow the inbound email webhook tutorial.