Skip to content

coder-msk/Automatic-Email-Response-and-Draft-Creation

Repository files navigation

Automatic Email Response & Draft Creation

An n8n workflow for Gmail that classifies new unread mail with an OpenAI-powered agent, then either sends a short auto-reply (generic / bulk mail) or creates a Gmail draft (messages that need a real reply). You keep control: non-generic mail becomes an editable draft instead of sending automatically.

Repository: github.com/coder-msk/Automatic-Email-Response-and-Draft-Creation


Features

Behavior When
Auto-reply in the thread Email is classified as GENERIC (newsletters, promos, receipts, automated notices, etc.). Reply goes to the sender only.
Gmail draft (Re: …) Email is classified as NON_GENERIC (personal or business mail that expects a thoughtful reply).

The model returns structured JSON: classification, reasoning, and suggestedReply. An If node branches on classification.


How it works

flowchart LR
  A[Gmail: new unread] --> B[Set fields]
  B --> C[AI: classify + suggest reply]
  C --> D{GENERIC?}
  D -->|yes| E[Send auto reply]
  D -->|no| F[Create draft]
Loading
  1. New Unread Email — Gmail trigger (e.g. poll every minute).
  2. Workflow Configuration — Maps subject, body, from, messageId, threadId.
  3. Classify Email — LangChain agent with a system prompt for GENERIC vs NON_GENERIC and reply tone.
  4. OpenAI Chat Model + Structured Output Parser — Keeps output in a fixed JSON shape (second chat model supports the parser).
  5. Is Generic Email? — Routes to Send Auto Reply or Create Draft.
  6. Send Auto Reply / Create Draft — Gmail nodes using thread metadata and suggestedReply.

Screenshots

Generic path — workflow canvas

n8n view of the branch that sends an automatic reply for generic mail:

n8n workflow — generic email path

Non-generic path — workflow canvas

n8n view of the branch that creates a draft for non-generic mail:

n8n workflow — non-generic email path


Requirements

  • n8n with Gmail and LangChain nodes (compatible with the version used when the workflow was exported).
  • Gmail OAuth2 — used by the trigger and Gmail send/draft nodes.
  • OpenAI API — e.g. gpt-4o-mini for the agent and parser chat models.

Import and setup

  1. In n8n: WorkflowsImport from File → select
    Automated Email Response & Draft Creation.json.
  2. Open every node that uses credentials and attach your own Gmail and OpenAI credentials (exported workflows often still show IDs from the original instance).
  3. Adjust New Unread Email (poll interval and Gmail filters) to match your inbox.
  4. Activate the workflow when you are satisfied with tests.

Security: API keys and OAuth tokens live in n8n credentials, not inside the JSON file. Do not commit secrets; re-credential after import on a new instance.


Repository layout

Path Purpose
Automated Email Response & Draft Creation.json Exported n8n workflow (import this).
Send Auto Reply for Generic Emails/ Workflow screenshot for the generic / auto-reply path.
Create Draft for Non-Generic Emails/ Workflow screenshot for the non-generic / draft path.
email classification.docx Optional notes on classification (not required to run the workflow).

License

Add a LICENSE file if you want to specify terms for reuse.

About

AI-Powered Gmail Filter & Auto-Responder. Uses GPT-4o to classify mail as Generic (Auto-Reply) or Non-Generic (Draft Creation). Smart inbox management via n8n.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors