The problem
A shared info@ or ops@ inbox gets a hundred emails a day and the person on duty reads all of them to find the twenty that need something. Replies go out late, tasks hide in threads, and nobody can say afterwards what was handled or why.
Architecture
- Channel
- Shared Gmail inbox
- Classify emails button
- Agent
- Apps Script Gmail add-on
- Gemini with a fixed prompt
- Tools
- Gmail labels and drafts
- Google Sheets log
- Human
- Person sends every reply
- Person moves tasks to board
Where the data stays: Mail stays in Gmail and decisions in a restricted Sheet; Gemini runs in your own Google Cloud project.
Design flow
- Collect unread emails from the last 7 days
- Gemini sorts: reply, action or FYI
- Matching Gmail label applied
- Draft reply for needs-response emailsOnly sometimes
- Email, category and reason logged
- Person reviews drafts before sendingHuman checkpoint
Setup
Total time: 2 h 5 min our estimate
- 20 min
Done when: In your own Google Cloud project the Gemini (Vertex AI), Gmail and Sheets APIs show as enabled.
- 30 min
The test deployment installs the add-on for the account you are signed in with, so build and install it as the shared inbox account.
Done when: The project is linked to the Cloud project number, holds every .gs file from the Email Classifier sample, and Constants.gs has your PROJECT_ID and name.
- 15 min
Done when: The consent screen exists with audience Internal and your support and contact email.
- 10 min
Done when: Email Classifier appears in Gmail's right sidebar and its Create labels button has added the three labels.
- 30 min
Done when: After Classify emails, the linked Sheet has a row per unread email with category and reason, and you agree with the sorting of a morning's mail.
- 20 min
The sample has basic error handling only: add retries and watch API rate limits before you run it every day.
Done when: Every needs-response draft was read, edited or deleted by the person on duty, and nothing left Gmail without them.
Ticks are saved on this browser.
Risks and data
Data
Subjects and bodies sent to the model may carry customer personal data. Run it in your own Google Cloud project with an Internal consent screen, restrict the log Sheet to the team that owns the inbox, and leave out mailboxes that handle HR or health matters.
How it goes wrong
An urgent email filed as FYI waits unseen, or a batch stops halfway on a rate limit or an unhandled error. The Sheet logs every email with its category and reason, so a scan of the FYI rows catches mis-sorts, a short log shows a broken run, and nothing goes out because a person sends every reply.
How the agent works
It starts
On a schedule, or when the duty person clicks a button in the Gmail side panel, the agent collects unread emails from the last seven days and sends the subject and body of each to Gemini with a fixed prompt.
The agent works
Each email is classified as needs-response, action-required or for-your-info and gets the matching Gmail label. For needs-response emails the agent writes a draft reply in Gmail; for action-required ones it logs the task. Every email, its category and the reason are appended to a Google Sheet so the team can audit the decisions.
The result
A person reviews the drafts before sending and moves tasks to the task board; the agent never sends mail.
Worked example
Google's own Apps Script samples repository ships this as the Email Classifier add on: it processes unread emails from the last seven days, classifies each into needs-response, action-required or for-your-info, applies the label, generates draft replies for the needs-response group and logs each email's details, classification and reason to a Google Sheet. A sibling sample in the same repository labels emails with an upset tone using Gemini on Vertex AI. Google notes the sample has only basic error handling, so harden it before daily use.
Apps Script can call the Claude or OpenAI API with the same prompt in place of Gemini, and Make, n8n or Zapier can run the same Gmail to Sheets flow without code.
Join the Agent OS Club
Get hours back with a team of AI agents for every department, set up step by step for the tools you use, with a person answering your questions. Founding member price: USD 14.95 a month or USD 150 a year, locked for as long as you stay. Cancel any time.
Founding offer, ends 31 December 2026 or at member 100
Join the Agent OS ClubBuilding this for an organization? Learn more at theagentiv.com
Sources
- https://github.com/googleworkspace/apps-script-samples/tree/main/ai/email-classifier
- https://github.com/googleworkspace/apps-script-samples/tree/main/gmail-sentiment-analysis
Published: 2026-10-16