Dev.to AI 🤖 Ai 👁 0 📖 5 min read

How to send AI follow-up emails in n8n when a lead doesn't reply (Google Sheets + Gmail)

Most leads don't say no. They just go quiet. A short, polite follow-up three days later wins back a surprising number of them, but nobody remembers to send it. In this tutorial we'll build an n8n workflow that: Runs e

Most leads don't say no. They just go quiet. A short, polite follow-up three days later wins back a surprising number of them, but nobody remembers to send it.

In this tutorial we'll build an n8n workflow that:

  1. Runs every morning at 9am
  2. Reads your leads from a Google Sheet
  3. Picks the ones who haven't replied for X days
  4. Asks an LLM to write a short follow-up with a new angle each time
  5. Sends it from Gmail, updates the sheet, and stops after 3 attempts

It takes about 20 minutes and uses only built-in n8n nodes. No community nodes, no code beyond a few expressions.

What you need

  • n8n (Cloud or self-hosted, v1.60+)
  • A Google account (Sheets + Gmail credentials in n8n)
  • An OpenAI-compatible API key (OpenAI, OpenRouter, Groq, DeepSeek or a local Ollama all work, because we call /chat/completions directly)

Step 1: The sheet

Create a sheet called Leads with these columns:

email name message status last_contact followups_sent
[email protected] Sam Need a new website before Dec contacted 2026-11-10 0

The workflow only cares about rows where status is contacted. When someone replies, you change their status to replied and they drop out of the sequence automatically. That one column is your "stop" button.

Step 2: Workflow overview

Schedule (9am) → Config → Read Leads → Filter (due?) → Loop
   → AI: write follow-up → Parse JSON → Gmail send → Update row → Save to Sheet

Step 3: A Config node (do this first)

Add a Set node called Config straight after the trigger. Put every value you might want to change here:

field example
business_name Acme Studio
business_offer website design for local businesses
sender_name Alex from Acme Studio
ai_base_url https://api.openai.com/v1
ai_model gpt-4o-mini
sheet_url (your sheet URL)
sheet_tab Leads
days_between 3
max_followups 3

Every other node reads from it with $('Config').first().json.<field>. When you later switch models or change the wait time, you edit one node instead of hunting through five.

Step 4: Read only the leads that are due

Google Sheets → Read rows, with a filter status = contacted.

Then a Filter node with two conditions (AND):

Days since last contact is at least days_between:

{{ $now.diff(DateTime.fromISO(String($json.last_contact)), 'days').days }}
>=  {{ $('Config').first().json.days_between }}

Fewer than max_followups already sent:

{{ Number($json.followups_sent || 0) }}
<  {{ $('Config').first().json.max_followups }}

Number(... || 0) matters: an empty cell comes in as "", and you don't want that to break the comparison.

Step 5: Loop one lead at a time

Add Loop Over Items (Split in Batches). Sending one at a time keeps Gmail happy and means one bad AI response doesn't sink the whole run.

Step 6: Let the AI write it, with a new angle each time

The trick that makes follow-ups not feel like spam is never repeating yourself. We tell the model which follow-up number this is and give each number a different job:

  • #1: gentle check-in plus one helpful tip
  • #2: a short result or mini case study
  • #3: a polite "closing the file" email (these get the most replies, oddly)

Use an HTTP Request node (POST {{ ai_base_url }}/chat/completions) with this JSON body:

{{ JSON.stringify({
  model: $('Config').first().json.ai_model,
  temperature: 0.3,
  response_format: { type: 'json_object' },
  messages: [
    { role: 'system', content:
      "You write follow-up emails for " + $('Config').first().json.business_name +
      " (" + $('Config').first().json.business_offer + "). " +
      "The lead has not replied. Write follow-up number N. Rules: max 70 words, warm and human, " +
      "a NEW angle each time (1 = check-in + tip, 2 = short result, 3 = polite closing-the-file). " +
      "Same language as the lead's message. Return JSON: {\"subject\": string, \"body\": string}" },
    { role: 'user', content: JSON.stringify({
      n: Number($json.followups_sent || 0) + 1,
      name: $json.name,
      original_message: $json.message
    }) }
  ]
}) }}

Two details worth copying:

  • response_format: json_object plus "Return JSON" in the prompt gives you a clean {subject, body} almost every time.
  • "Same language as the lead's message" means a lead who wrote in Spanish gets a Spanish follow-up, for free.

Step 7: Parse safely

LLMs occasionally return something that isn't valid JSON. A small Code node (run once for each item) makes sure the workflow never crashes on it:

const defaults = { subject: "Quick follow-up", body: "" };
let parsed = {};
try {
  parsed = JSON.parse($json.choices[0].message.content);
} catch (e) {
  parsed = { ai_error: 'Could not parse AI response' };
}
return { json: { ...defaults, ...parsed } };

Optional: add an IF node after it that skips sending when body is empty, so you never email a blank message.

Step 8: Send and update the sheet

Gmail → Send:

  • To: {{ $('Loop Over Items').item.json.email }}
  • Subject: {{ $json.subject }}
  • Message: {{ $json.body }} plus your sign-off
  • Turn off "Append n8n attribution"

Then a Set node that prepares the row update:

// email
{{ $('Loop Over Items').item.json.email }}

// followups_sent
{{ Number($('Loop Over Items').item.json.followups_sent || 0) + 1 }}

// last_contact
{{ $now.toFormat("yyyy-MM-dd") }}

// status
{{ Number($('Loop Over Items').item.json.followups_sent || 0) + 1 >= $('Config').first().json.max_followups
   ? 'closed-no-reply' : 'contacted' }}

And Google Sheets → Update row, matching on email. After the third follow-up the status becomes closed-no-reply and the lead leaves the loop for good.

Connect the end back to the loop node and you're done.

Testing it without emailing real people

  1. Add a row with your own email and last_contact set to a week ago.
  2. Swap the Gmail node's operation from Send to Create draft for the first run.
  3. Click Execute workflow and check your drafts. Read all three angles by resetting followups_sent to 0, 1 and 2.

Ideas to extend it

  • Detect replies automatically: a Gmail trigger that sets status = replied when a known lead emails you, so you never have to update the sheet by hand.
  • Score leads first so only warm leads get the full sequence.
  • Weekly report: every Monday, count contacted / replied / closed and send yourself the numbers.

If you'd rather import this ready-made, it's one of five connected workflows (instant AI reply + lead scoring, inbox triage, this follow-up sequence, review requests and a weekly pipeline report, all sharing one Google Sheet) in LeadPilot. But everything above is enough to build it yourself.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.