domainwidedelegation.comStart free

Use casesEmail operations

Automate labelling of incoming emails using delegation

Apply labels to inbound mail across mailboxes for routing, compliance or workflow using a service account with domain-wide delegation.

Who it is forIT automation teams or operations teams needing consistent mail classification.
APIsGmail API
Typical scopesgmail.modify

The problem

Manual labelling is error-prone and not scalable. Built-in rules are limited and cannot express complex business logic, and user-maintained filters drift out of sync.

How it works

  1. Register a service account and configure domain-wide delegation for gmail.modify.
  2. Poll each mailbox for new messages, filtering by historyId or receivedAfter to avoid reprocessing.
  3. Apply labels using users.messages.modify for matching messages.
  4. Log message IDs and applied labels for audit and troubleshooting.
  5. Handle rate limits and batch label operations where possible.

What changes

New mail is labelled according to centrally managed rules, improving downstream routing, searching and compliance without user intervention.

The trap in this one. The Gmail API’s historyId is only monotonically increasing within a single mailbox, not globally. If you track one global cursor across accounts, you will miss messages that arrive in parallel mailboxes. Always store a per-user cursor; otherwise, you will silently skip labelling emails for some users, especially during high-volume periods or after service disruptions.

Watch it explained

Parse Email Body Data and Save it into (Google Sheets) | Apps script | Email Labels” — Outright Systems on YouTube. Third-party video, included because it covers this ground well. We are not affiliated with the channel.

Questions people ask

Can I use batch requests to label messages faster?

Yes, the Gmail API supports batchModify, but batch size is capped and hitting quota limits returns 429s. Implement retry with exponential backoff.

How do I avoid relabelling the same message?

Track processed message IDs or use historyId per-user to only process messages since the last successful run.

Want this built?

This is a pattern we run in production. We will set up the delegation and build this on top of it — $500 per hour, most of it working the same day.

Talk to us Or read the setup guide

Related use cases

Draft replies automatically in a shared inbox

A delegated service account reads an incoming enquiry, drafts a researched reply in the mailbox, and leaves it for a human to approve and send.

Triage and route inbound mail across a domain

Classify every inbound message, label it, and forward the ones that matter to the person who owns them — without touching a single mail rule.

Send mail as a shared alias from automation

Deliver notifications, confirmations and campaign replies from a branded address like support@ or updates@ without a human in the loop.