Recipe · Automation & AI agents
An n8n agent that watches a Gmail label and drafts the replies
Build a small n8n workflow: every email you tag with a Gmail label gets a reply drafted by an AI model and saved in the same thread as a Gmail draft. You read, edit and send; nothing goes out by itself.
Steps
- Open n8n: start a free n8n Cloud trial (nothing to install) or self-host the free Community Edition on a machine that stays on. Create a new, empty workflow.
- In Gmail, create a label called AI-draft. Optionally add a Gmail filter that applies it automatically (for example to mail from a client’s domain, or with “quote” in the subject); otherwise you will tag emails by hand.
- Add a Gmail Trigger node, event “Message Received”, and in its filters pick the AI-draft label. Turn the “Simplify” option off so the email body is included, and set polling to every 5 minutes. Connect your Google account (on n8n Cloud, sign in and allow access; self-hosted needs a Google Cloud OAuth client, which n8n’s Gmail credential docs walk through).
- Add an OpenAI “Message a model” node (or the AI Agent node with an OpenAI, Anthropic or Google chat model) and add an API key credential; the API is billed separately from a ChatGPT subscription. Put the template below in the system message and pass the email’s From, Subject and text in the user message using the expressions n8n shows when you drag fields from the trigger.
- Add a Gmail node, resource Draft, operation Create: Subject = “Re: ” + the original subject, Message = the model’s output, option “Send To” = the sender, and option “Thread ID” = the trigger’s threadId so the draft sits inside the conversation.
- Test: send yourself an email, apply the AI-draft label, run the workflow once by hand and open Gmail’s Drafts folder. When the draft looks right, switch the workflow to Active.
- Live with it for a week: edit the drafts before sending, and paste two or three of your real replies into the system message as examples so the tone matches yours. Add a second label like AI-done if you want to track which emails were drafted.
Agent template
Replace anything in { } with your details.
You draft email replies for {YOUR NAME}, {ROLE} at {COMPANY}. Reply in the language of the incoming email (Arabic or English).
Context about us: {2-3 LINES: what you offer, prices or links you may quote, working hours}.
Rules:
- Write a complete, polite reply to the email below, ready to send after a quick read. Under 150 words.
- Answer only what the email asks. If information is missing, say what you need instead of guessing. Never promise dates, discounts or refunds.
- Start with a greeting using the sender’s first name if present. Sign off as {YOUR NAME}.
- Output only the reply text: no subject line, no explanations.
Incoming email:
From: {{ $json.From }}
Subject: {{ $json.Subject }}
{{ $json.text }} Expected output
For every email with the AI-draft label, a Gmail draft in the same thread, in the sender’s language, within about five minutes; you send it after a read-through.
Gotchas
- ⚠ Keep it a draft. One auto-sent wrong answer to a customer costs more than the minutes you save.
- ⚠ The model’s API is billed separately from n8n and from ChatGPT: a ChatGPT Plus plan does not include OpenAI API credit, so expect a few cents per email on a pay-as-you-go key.
- ⚠ n8n Cloud’s trial ends; after that the Starter plan is $24/mo, or self-host for free on a machine that stays on.
- ⚠ The whole email goes to the model provider. Use a work account, skip the label on anything confidential, and check your company’s data policy.
- ⚠ Gmail OAuth on a self-hosted n8n needs a Google Cloud project and a consent screen; budget 20 extra minutes the first time.