▶ Stepthrough All tutorials Blog Glossary Prompts Videos Visual guides Cheat sheets Start Learning Free

AI Email Responder: Draft Gmail Replies Automatically with n8n: step-by-step guide with screenshots

Updated

Build an n8n agent that watches your Gmail, reads each new customer email, and writes a reply as a draft in the same thread, ready for you to check and send.

About the screenshots. They come from Stepthrough’s simulated practice environment (a practice copy of n8n), not the live tool, so no real account appears. The buttons and labels match the real screens the lesson was built against. Practice it yourself free at learn.ynteractive.com.

Part 1: The email

Step 1: Look at the inbox

In this module you're the office at Greenline Pest Control, and customers email the same questions all day. Do you cover my area? What does it cost? Let's build an agent that writes those replies for you. First, look at the inbox. Switch to the Gmail tab.

N8n in Stepthrough’s practice copy, step 1 of 63 (Look at the inbox): the cursor is on “Gmail”, highlighted.
Step 1 of 63. You're the office at Greenline Pest Control. Switch to the Gmail tab.

Step 2: Open the email

There's a new one from Dana.

Gmail in Stepthrough’s practice copy, step 2 of 63 (Open the email): the cursor is on “the email”, highlighted.
Step 2 of 63. Open Dana's email.

Step 3: Back to n8n

Ants in the kitchen, is Maple Grove covered, and roughly what does it cost. A person could answer that in two minutes. The agent will do it in seconds. Back to the n8n tab.

Gmail in Stepthrough’s practice copy, step 3 of 63 (Back to n8n): the cursor is on “n8n”, highlighted.
Step 3 of 63. Ants, an area and a price question. Switch back to n8n.

Part 2: Gmail trigger

Step 4: Create a workflow

The n8n overview page in Stepthrough’s practice copy, step 4 of 63 (Create a workflow): the cursor is on “Create workflow”, highlighted.
Step 4 of 63. Click Create workflow.

Step 5: Add the trigger

Every workflow starts with a trigger, the event that kicks everything off. Here, that's a new email arriving.

The n8n workflow canvas in Stepthrough’s practice copy, step 5 of 63 (Add the trigger): the cursor is on “Add first step”, highlighted.
Step 5 of 63. Click Add first step.

Step 6: Search for Gmail

The n8n node list in Stepthrough’s practice copy, step 6 of 63 (Search for Gmail): the gmail is filled in (“gmail”).
Step 6 of 63. Type gmail.

Step 7: Gmail

The n8n node list in Stepthrough’s practice copy, step 7 of 63 (Gmail): the cursor is on “Gmail”, highlighted.
Step 7 of 63. Click Gmail.

Step 8: On message received

Under triggers, click on message received. That adds the Gmail trigger.

The n8n node list in Stepthrough’s practice copy, step 8 of 63 (On message received): the cursor is on “Triggers”, highlighted.
Step 8 of 63. Under Triggers, click On message received.

Part 3: Connect Gmail

Step 9: Credential

n8n needs permission to read the inbox.

An n8n node’s settings window in Stepthrough’s practice copy, step 9 of 63 (Credential): the cursor is on “Credential”, highlighted.
Step 9 of 63. Open the Credential dropdown.

Step 10: New credential

Create new credential.

A dropdown menu in n8n in Stepthrough’s practice copy, step 10 of 63 (New credential): the cursor is on “Create new credential”, highlighted.
Step 10 of 63. Click Create new credential.

Step 11: Sign in with Google

Leave it on managed OAuth and click sign in with Google.

The Google sign-in window in Stepthrough’s practice copy, step 11 of 63 (Sign in with Google): the cursor is on “Sign in with Google”, highlighted.
Step 11 of 63. Click Sign in with Google.

Step 12: Pick the inbox

Pick the inbox customers write to. For Greenline, that is the office account.

The Google sign-in window in Stepthrough’s practice copy, step 12 of 63 (Pick the inbox): the cursor is on “office@greenlinepest.com”, highlighted.
Step 12 of 63. Pick the business inbox, [email protected].

Step 13: Allow access

Google spells out what n8n can do with your mail. That list sounds big. What actually happens is decided by the nodes you add, and ours will only read and write drafts.

The Google sign-in window in Stepthrough’s practice copy, step 13 of 63 (Allow access): the cursor is on “Continue”, highlighted.
Step 13 of 63. Click Continue.

Step 14: Fetch a test email

Look at the settings. It checks every minute, and it fires on message received. Both are what we want. n8n grabs the newest email so we can see what it looks like.

The n8n trigger settings in Stepthrough’s practice copy, step 14 of 63 (Fetch a test email): the cursor is on “Every Minute”, highlighted.
Step 14 of 63. Leave Every Minute and Message Received as they are. Click Fetch Test Event.

Part 4: Gmail trigger

Step 15: Close the node

There's Dana's email, broken into fields. From, subject, a snippet of the message, and a thread I D. Think of it as one row in a spreadsheet. We'll use these fields next. Close it.

An n8n node’s settings window in Stepthrough’s practice copy, step 15 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 15 of 63. There's Dana's email as data: From, Subject, snippet and a threadId. Close the node.

Part 5: AI Agent

Step 16: Add the next step

Now, what should happen with that email.

The n8n workflow canvas in Stepthrough’s practice copy, step 16 of 63 (Add the next step): the cursor is on “+”, highlighted.
Step 16 of 63. Click the + after the Gmail Trigger.

Step 17: Search for the agent

The n8n node list in Stepthrough’s practice copy, step 17 of 63 (Search for the agent): the agent is filled in (“agent”).
Step 17 of 63. Type agent.

Step 18: AI Agent

AI Agent.

The n8n node list in Stepthrough’s practice copy, step 18 of 63 (AI Agent): the cursor is on “AI Agent”, highlighted.
Step 18 of 63. Click AI Agent.

Step 19: Change the prompt source

This is the part people miss. By default the agent expects a chat message, but our input is an email.

An n8n node’s settings window in Stepthrough’s practice copy, step 19 of 63 (Change the prompt source): the cursor is on “Source for Prompt”, highlighted.
Step 19 of 63. Open Source for Prompt.

Step 20: Define below

Define below. Now we write the prompt ourselves.

A dropdown menu in n8n in Stepthrough’s practice copy, step 20 of 63 (Define below): the cursor is on “Define below”, highlighted.
Step 20 of 63. Choose Define below.

Step 21: Write the prompt

It tells the agent to write a reply and save it as a draft in the same thread. The bits in double curly brackets are expressions. Each one pulls in a field from the email. Who it's from, the subject, and the message. On the left you can see those same fields from the test email.

An n8n node’s settings window in Stepthrough’s practice copy, step 21 of 63 (Write the prompt): the prompt is filled in (“Write a reply to this email, then save it as a…”).
Step 21 of 63. Paste the prompt. The parts in {{ }} pull in fields from the email.
Write a reply to this email, then save it as a draft in the same thread.
<email>
From: {{ $json.From }}
Subject: {{ $json.Subject }}
Message: {{ $json.snippet }}
</email>

Step 22: Close the node

The agent knows what to do with each email. It doesn't know anything about the business yet. We'll come back for that. Close it.

An n8n node’s settings window in Stepthrough’s practice copy, step 22 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 22 of 63. We'll add the business details later. Close the agent.

Part 6: Chat model

Step 23: Add the model

Give it a brain.

The n8n workflow canvas in Stepthrough’s practice copy, step 23 of 63 (Add the model): the cursor is on “+”, highlighted.
Step 23 of 63. Click the + under Chat Model.

Step 24: Search for OpenAI

The n8n node list in Stepthrough’s practice copy, step 24 of 63 (Search for OpenAI): the openai is filled in (“openai”).
Step 24 of 63. Type openai.

Step 25: OpenAI Chat Model

OpenAI chat model.

The n8n node list in Stepthrough’s practice copy, step 25 of 63 (OpenAI Chat Model): the cursor is on “OpenAI Chat Model”, highlighted.
Step 25 of 63. Click OpenAI Chat Model.

Step 26: Credential

An n8n node’s settings window in Stepthrough’s practice copy, step 26 of 63 (Credential): the cursor is on “Credential”, highlighted.
Step 26 of 63. Open the Credential dropdown.

Step 27: Reuse your OpenAI key

Pick OpenAI account, the key you saved in Module 2. The default model is fine. Writing a short email is an easy job.

A dropdown menu in n8n in Stepthrough’s practice copy, step 27 of 63 (Reuse your OpenAI key): the cursor is on “OpenAI account”, highlighted.
Step 27 of 63. Choose OpenAI account, the key from Module 2.

Step 28: Close the node

Close it.

An n8n node’s settings window in Stepthrough’s practice copy, step 28 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 28 of 63. Close the model.

Part 7: Draft tool

Step 29: Add a tool

Now the tool that lets the agent act on its answer.

The n8n workflow canvas in Stepthrough’s practice copy, step 29 of 63 (Add a tool): the cursor is on “+”, highlighted.
Step 29 of 63. Click the + under Tool.

Step 30: Search for Gmail

The n8n node list in Stepthrough’s practice copy, step 30 of 63 (Search for Gmail): the gmail is filled in (“gmail”).
Step 30 of 63. Type gmail.

Step 31: Gmail Tool

Gmail tool.

The n8n node list in Stepthrough’s practice copy, step 31 of 63 (Gmail Tool): the cursor is on “Gmail Tool”, highlighted.
Step 31 of 63. Click Gmail Tool.

Step 32: Credential

An n8n node’s settings window in Stepthrough’s practice copy, step 32 of 63 (Credential): the cursor is on “Credential”, highlighted.
Step 32 of 63. Open the Credential dropdown.

Step 33: Same Gmail account

Pick Gmail account. It's the one you just connected for the trigger. No need to sign in again.

A dropdown menu in n8n in Stepthrough’s practice copy, step 33 of 63 (Same Gmail account): the cursor is on “Gmail account”, highlighted.
Step 33 of 63. Choose Gmail account, the one you just connected.

Step 34: Resource

Careful here. It's set to message, and the operation is send. We do not want an agent sending emails on its own.

An n8n node’s settings window in Stepthrough’s practice copy, step 34 of 63 (Resource): the cursor is on “Resource”, highlighted.
Step 34 of 63. Open the Resource dropdown. It says Message.

Step 35: Draft

Draft. The operation switches to create. So the worst this agent can do is write a draft you never send.

A dropdown menu in n8n in Stepthrough’s practice copy, step 35 of 63 (Draft): the cursor is on “Draft”, highlighted.
Step 35 of 63. Choose Draft. Operation switches to Create.

Step 36: Keep the subject

Subject. A reply keeps the original subject with R E in front, or Gmail may not keep it in the same conversation. It's R E, then the subject from the email.

An n8n node’s settings window in Stepthrough’s practice copy, step 36 of 63 (Keep the subject): the expression is filled in (“Re: {{ $json.Subject }}”).
Step 36 of 63. Paste Re: {{ $json.Subject }} into Subject.

Step 37: Let the model write the message

The message is the part we can't know ahead of time. The agent writes it. Email type stays on text, because plain text reads more like a person than fancy formatting.

An n8n node’s settings window in Stepthrough’s practice copy, step 37 of 63 (Let the model write the message): the cursor is on “Message”, highlighted.
Step 37 of 63. Next to Message, click the ✦ button.

Step 38: Add an option

One more thing, and it's important. Without it, the draft lands as a brand new email instead of a reply.

An n8n node’s settings window in Stepthrough’s practice copy, step 38 of 63 (Add an option): the cursor is on “Add option”, highlighted.
Step 38 of 63. Click Add option.

Step 39: Thread ID

Thread I D.

A dropdown menu in n8n in Stepthrough’s practice copy, step 39 of 63 (Thread ID): the cursor is on “Thread ID”, highlighted.
Step 39 of 63. Choose Thread ID.

Step 40: Point it at the thread

It's the thread I D from the Gmail trigger, so the draft sits right under Dana's email, as a reply.

An n8n node’s settings window in Stepthrough’s practice copy, step 40 of 63 (Point it at the thread): the expression is filled in (“{{ $json.threadId }}”).
Step 40 of 63. Paste {{ $json.threadId }}.

Step 41: One more option

One more. The thread I D puts the draft in the right conversation, but it doesn't fill in who it goes to. Without a recipient, you couldn't just hit send.

An n8n node’s settings window in Stepthrough’s practice copy, step 41 of 63 (One more option): the cursor is on “Add option”, highlighted.
Step 41 of 63. Click Add option again.

Step 42: To Email

To email.

A dropdown menu in n8n in Stepthrough’s practice copy, step 42 of 63 (To Email): the cursor is on “To Email”, highlighted.
Step 42 of 63. Choose To Email.

Step 43: Reply to the sender

It's the from field of the email, so the reply goes back to whoever wrote in.

An n8n node’s settings window in Stepthrough’s practice copy, step 43 of 63 (Reply to the sender): the expression is filled in (“{{ $json.From }}”).
Step 43 of 63. Paste {{ $json.From }}.

Step 44: Close the node

Tool's done. Close it.

An n8n node’s settings window in Stepthrough’s practice copy, step 44 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 44 of 63. Close the tool.

Part 8: Memory

Step 45: Add memory

Last part: memory. If Dana writes back, the agent should remember what it already told her.

The n8n workflow canvas in Stepthrough’s practice copy, step 45 of 63 (Add memory): the cursor is on “+”, highlighted.
Step 45 of 63. Click the + under Memory.

Step 46: Simple Memory

Simple memory.

The n8n node list in Stepthrough’s practice copy, step 46 of 63 (Simple Memory): the cursor is on “Simple Memory”, highlighted.
Step 46 of 63. Click Simple Memory.

Step 47: Close the node

Leave the defaults for now and close it. Keep an eye on this one.

An n8n node’s settings window in Stepthrough’s practice copy, step 47 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 47 of 63. Leave the defaults for now. Close it.

Part 9: Instructions

Step 48: Open the agent

Now the business details. Without them the agent will guess prices, and that's how you end up promising something you don't do. Double click the AI agent.

The n8n workflow canvas in Stepthrough’s practice copy, step 48 of 63 (Open the agent): the cursor is on “AI Agent”, highlighted.
Step 48 of 63. Double-click AI Agent.

Step 49: Add an option

Add option.

An n8n node’s settings window in Stepthrough’s practice copy, step 49 of 63 (Add an option): the cursor is on “Add Option”, highlighted.
Step 49 of 63. Click Add Option.

Step 50: System Message

System message.

A dropdown menu in n8n in Stepthrough’s practice copy, step 50 of 63 (System Message): the cursor is on “System Message”, highlighted.
Step 50 of 63. Choose System Message.

Step 51: Give it the facts

It has four parts. The role. What it knows, meaning the service areas, prices and hours. The rules: it can only make drafts, and if it doesn't know something it says someone will follow up, never makes it up. And the style: friendly, short, plain text. Swap in your own details and this works for any business.

An n8n node’s settings window in Stepthrough’s practice copy, step 51 of 63 (Give it the facts): the system message is filled in (“Who you are: You write email replies for…”).
Step 51 of 63. Paste the system message: role, what it knows, rules, and style.
Who you are:
You write email replies for Greenline Pest Control, a family-run pest control company.

What you know:
- We service Maple Grove, Cedar Falls and Brookside.
- General pest treatment (ants, spiders, roaches): $149 for the first visit, $89 for a follow-up.
- We book Monday to Saturday, 8am to 5pm.
- To book, the customer replies with their address and two times that work.

Rules:
You cannot send email. You can only create drafts.
If you don't know something, say someone from the team will follow up. Never make up prices, dates or services.

How to write:
Friendly, plain and short. Plain text, not HTML. Sign off as "The Greenline team".

Step 52: Close the node

That's everything. Close it.

An n8n node’s settings window in Stepthrough’s practice copy, step 52 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 52 of 63. Close the agent.

Part 10: Test and fix

Step 53: Test it

Time to test. It runs on Dana's email.

The n8n workflow editor in Stepthrough’s practice copy, step 53 of 63 (Test it): the cursor is on “Execute workflow”, highlighted.
Step 53 of 63. Click Execute workflow.

Step 54: Open the memory

Red. Error in sub-node simple memory, no session I D found. Don't worry, this happens to everyone the first time. Double click the red memory node and let's see why.

The n8n workflow canvas in Stepthrough’s practice copy, step 54 of 63 (Open the memory): the cursor is on “No session ID found”, highlighted.
Step 54 of 63. It failed: No session ID found in Simple Memory. Double-click the red Simple Memory node.

Step 55: Find the problem

Here's the problem. Memory is looking for a chat session I D, and it comes back undefined, because an email is not a chat. It needs something else to tell conversations apart.

An n8n node’s settings window in Stepthrough’s practice copy, step 55 of 63 (Find the problem): the cursor is on “Session ID”, highlighted.
Step 55 of 63. It's looking for a chat session ID, and emails don't have one. Open Session ID.

Step 56: Define below

Define below.

A dropdown menu in n8n in Stepthrough’s practice copy, step 56 of 63 (Define below): the cursor is on “Define below”, highlighted.
Step 56 of 63. Choose Define below.

Step 57: Use the thread

Every email conversation has its own thread, so now memory keeps one conversation per customer. That's actually better than just deleting the memory, which is the quick fix you'll see a lot of people use.

An n8n node’s settings window in Stepthrough’s practice copy, step 57 of 63 (Use the thread): the expression is filled in (“{{ $json.threadId }}”).
Step 57 of 63. Paste {{ $json.threadId }} as the key.

Step 58: Close the node

An n8n node’s settings window in Stepthrough’s practice copy, step 58 of 63 (Close the node): the cursor is on “Close the node”, highlighted.
Step 58 of 63. Close it.

Step 59: Test again

Execute workflow again.

The n8n workflow editor in Stepthrough’s practice copy, step 59 of 63 (Test again): the cursor is on “Execute workflow”, highlighted.
Step 59 of 63. Click Execute workflow again.

Part 11: Check the draft

Step 60: Check Gmail

All green. Switch to Gmail and see what it wrote.

The n8n workflow editor in Stepthrough’s practice copy, step 60 of 63 (Check Gmail): the cursor is on “Gmail”, highlighted.
Step 60 of 63. Everything is green. Switch to the Gmail tab.

Step 61: Read the draft, then go back

There it is, a draft, right under Dana's email. Yes to Maple Grove, a hundred forty nine for the first visit, and it asks for her address and two times, exactly like we told it. And it has not been sent. You read it, then you hit send. Now go back to n8n.

Gmail in Stepthrough’s practice copy, step 61 of 63 (Read the draft, then go back): the cursor is on “n8n”, highlighted.
Step 61 of 63. The draft sits under Dana's email. Right area, right prices, not sent. Switch back to n8n.

Step 62: Turn it on

Last step. Right now it only runs when you press execute.

The n8n workflow editor in Stepthrough’s practice copy, step 62 of 63 (Turn it on): the cursor is on “Publish”, highlighted.
Step 62 of 63. Click Publish.

Step 63: Publish it

n8n asks for a version name. The default is fine. Every new email gets a draft waiting for you.

The n8n Publish dialog in Stepthrough’s practice copy, step 63 of 63 (Publish it): the cursor is on “Publish”, highlighted.
Step 63 of 63. Leave the version name as it is. Click Publish.

Now do it yourself, free

Reading the steps is a start. Doing them is how it sticks. The interactive lesson puts you in a practice copy of n8n: you do every step yourself, it checks your work, and “Do it for me” finishes any step you get stuck on. Nothing touches your real accounts.

Practice “AI Email Responder: Draft Gmail Replies Automatically with n8n” step by step

AI Email Responder: Draft Gmail Replies Automatically with n8n: lesson overview · All free tutorials