March 27, 2026
6 min read
Share article

How to Build an AI Email Assistant That Responds to Leads Automatically

AI email assistant automatically responding to leads using n8n and OpenAI

The average response time for a business replying to a new lead is 47 hours. The average response time that maximizes conversion is under 5 minutes. That gap is where AI email automation wins.

In this tutorial, you'll build an AI email assistant in n8n that monitors a Gmail inbox, reads incoming lead emails, qualifies the lead using OpenAI, and sends a personalized response automatically — all within 60 seconds of the email arriving.

What You'll Build

  • Gmail trigger watching for new emails in a specific label or inbox
  • Email parsing to extract lead information
  • OpenAI-powered lead qualification and scoring
  • Personalized response generation based on lead context
  • Automatic reply sent from Gmail
  • CRM entry for the new lead
  • Slack notification with the lead summary and AI response preview

Step 1: Set Up Gmail Trigger

In n8n, add a Gmail Trigger node as your workflow entry point:

  • Event: Message Received
  • Credentials: connect your client's Gmail via OAuth
  • Filters: only trigger on emails matching certain criteria

For filtering, use one of these approaches:

  • Watch a specific Gmail Label (e.g., "New Leads") — manually label or use a Gmail filter to auto-label contact form submissions
  • Filter by sender domain patterns in a Code node
  • Filter by subject line keywords like "inquiry" or "contact form"

The simplest approach: in Gmail, create a filter that applies the label "n8n-leads" to emails from your contact form or from specific domains, then configure n8n to watch that label.

Step 2: Parse the Email Content

Add a Code node to extract structured data from the email:

const email = $input.first().json; const body = email.text || email.snippet || ''; const subject = email.subject || ''; const fromEmail = email.from?.value?.[0]?.address || ''; const fromName = email.from?.value?.[0]?.name || ''; return [{ json: { from_email: fromEmail, from_name: fromName, subject, body, message_id: email.id, thread_id: email.threadId } }];

For contact form submissions, the email body typically follows a template. You can use a more targeted regex or simply pass the full body to OpenAI for extraction.

Step 3: Extract Lead Information with OpenAI

Add an OpenAI node to extract structured lead data from the email body:

  • Model: gpt-4o-mini
  • System: "Extract structured lead information from email content. Return a JSON object with: name, email, phone, company, message, inquiry_type (sales/support/other), urgency (high/medium/low)."
  • User message: Email from: {{$json.from_name}} {{$json.from_email}}. Subject: {{$json.subject}}. Body: {{$json.body}}
  • Response Format: JSON Object

Step 4: Qualify the Lead

Add a second OpenAI node for qualification scoring:

  • System: "You are a B2B sales qualification expert. Score this lead from 1-10 and classify them as hot/warm/cold. Consider: urgency, budget signals, company size indicators, and specificity of request."
  • User: pass the extracted lead data from the previous step
  • Output JSON: { "score": 1-10, "classification": "hot/warm/cold", "key_buying_signals": [], "recommended_response_tone": "urgent/professional/informational" }

Step 5: Generate the Personalized Response

Add a third OpenAI node to write the actual email response:

  • System: your client's email assistant persona — include their name, business, tone, and key value props
  • User: "Write a reply to this lead inquiry. Lead name: {{$json.name}}. Inquiry: {{$json.message}}. Tone: {{$json.recommended_response_tone}}. Include a clear CTA to book a call or schedule a demo. Keep it under 150 words. Sign off as [Rep Name] from [Business Name]."

Example system prompt:

You are Sarah, a sales assistant at Apex Plumbing. You are friendly, helpful, and professional. Our key services: emergency plumbing, drain cleaning, water heater installation. Our book-a-call link: calendly.com/apex-plumbing. Never make up pricing — say 'we can provide a free estimate on your call.'

Step 6: Add Human-in-the-Loop Safety Check

For high-stakes clients, you may want a human approval step before auto-sending. Add an IF node:

  • If lead_score >= 8 (hot lead) → send to Slack for human approval before sending
  • If lead_score < 8 (warm/cold) → auto-send the AI response

For Slack approval, use the Slack → Send Message node with action buttons (yes/no). This requires the Slack app to have interactive components enabled.

For most use cases, just auto-send everything — clients love seeing immediate responses go out.

Step 7: Send the Auto-Reply

Add a Gmail → Reply to a Message node:

  • Message ID: {{$json.message_id}}
  • Thread ID: {{$json.thread_id}}
  • Reply Body (HTML): {{$json.ai_response}}
  • From: your client's Gmail address

The reply goes into the same Gmail thread, so it looks like a natural conversation. The lead sees a personalized response from a named person, not an obviously automated message.

Step 8: Create the CRM Entry

Add a HubSpot or Pipedrive node to create the contact and deal:

  • Create Contact: name, email, phone, company (from AI extraction)
  • Create Deal: inquiry type as deal name, hot/warm/cold as deal stage
  • Add a note with the full email content and AI qualification summary

Step 9: Notify the Sales Team

Add a Slack node with a rich message block:

  • Include lead name, company, score, classification
  • Include a preview of the AI-generated response that was sent
  • Include a link to the CRM record
  • Use emoji to make hot leads stand out: 🔥 for score 8+, 🟡 for 5-7, ⚪ for below 5

Step 10: Handle Edge Cases

Add an IF node at the start to skip certain emails:

  • Skip if sender is a known spam domain
  • Skip if the email contains "unsubscribe" (it's a marketing email)
  • Skip if sender is already an existing client (check CRM first)
  • Skip if it's a reply to an existing thread (you don't want the bot replying to its own replies)

What to Charge for This

This workflow typically sells for $800–$2,000 setup (includes custom prompts, CRM integration, and testing) plus $200–$400/month ongoing. The pitch: "Your leads get a personalized response within 60 seconds, 24/7, with zero effort from your team."

For the underlying n8n skills to build this, see our n8n AI agent beginner's guide. To compare n8n with other platforms for this use case, read our n8n vs Make vs Zapier comparison.

Want to learn how to build and sell AI automations? Join our free community. Join the free AI Agency Sprint community.
Community & Training

Join 215+ AI Agency Owners

Get free access to our LinkedIn automation tool, AI content templates, and a community of builders landing clients in days.

Access the Free Sprint
22 people joined this week