An AI agent that monitors a Gmail inbox, classifies incoming emails, applies the right label, and drafts a ready-to-send reply — so a human only needs to review and hit send.
Responding to repetitive inbound emails (student doubts, course questions, sponsorship requests) takes time and mental switching. This assistant reads each new email, understands its intent, sorts it into the right category, and prepares a thoughtful draft reply — reducing response time while keeping a human in control of what actually gets sent.
Trigger → Fetch → Agent (classify + draft) → Label → Draft
- Gmail Trigger — polls the inbox every minute for new mail.
- Get Many Messages — retrieves the latest message content (subject + snippet).
- AI Agent (LangChain) — the core of the flow. Given the email's subject and body, it:
- Classifies the email into one of three labels:
Course,Doubt, orSponsorship - Looks up the correct Gmail label ID using the Gmail labels tool
- Drafts a respectful, well-formatted HTML reply — explaining doubts in depth with examples where relevant
- Classifies the email into one of three labels:
- Structured Output Parser — forces the agent's output into a consistent JSON shape (label, label ID, subject, body, reply), making the downstream steps reliable.
- OpenAI Chat Model (gpt-5-mini) — powers the agent's classification and drafting.
- Add Label to Message — applies the classified label back onto the original Gmail message.
- Create a Draft — creates an HTML-formatted draft reply in Gmail, addressed to the original sender, left for human review before sending.
See workflow.json for the exact node configuration — import it into n8n to view the visual canvas.
- n8n (LangChain Agent, Structured Output Parser)
- OpenAI API — gpt-5-mini for classification and reply drafting
- Gmail API — OAuth2-connected for reading mail, managing labels, and creating drafts
- Import
workflow.jsoninto your n8n instance (Workflows → Import from File). - Set up credentials for:
- OpenAI API (your own API key)
- Gmail OAuth2 (connect your own Gmail account)
- In your Gmail account, create the three labels used by this flow:
Course,Doubt,Sponsorship(or adjust the agent's prompt to match your own label set). - Before publishing: clear or anonymize the
pinDatasection in the JSON — it contains a sample real email/message used during testing. - Activate the workflow. New emails will be checked every minute automatically.
- Draft, not auto-send: The workflow deliberately stops at creating a draft rather than sending the reply automatically. This keeps a human in the loop for quality and tone control — an important safeguard for anything client- or student-facing.
- Structured output parser over free-text parsing: Forcing the AI's response into a strict JSON schema (label, label_id, subject, body, reply) makes the downstream Gmail actions reliable, instead of trying to parse loosely-formatted text.
- Label classification via live lookup, not hardcoded IDs: The agent calls the Gmail "get labels" tool at runtime to fetch actual label IDs, rather than hardcoding them — making the flow portable across different Gmail accounts/label setups.
- HTML-formatted replies: Chosen specifically so drafts are easy to read and look professional when the sender opens them, rather than plain unformatted text.
- Only processes one new message at a time (
limit: 1) — could be extended to batch-process multiple unread emails per run. - Label categories are currently hardcoded in the prompt (Course/Doubt/Sponsorship) — a v2 could pull available labels dynamically and classify against the full list.
- No handling yet for attachments or multi-turn email threads — treats each email as a standalone message.
- Draft only — sending still requires manual review, by design, but could add an approval-triggered send step in future.