<aside>
Goal
Automate personalized email responses by combining contact data lookup with AI-generated replies, eliminating manual email handling while maintaining authentic, context-aware communication.
Solution
- Gmail trigger monitors incoming emails every minute
- Contact lookup retrieves customer history and notes from n8n Data Tables
- Claude AI generates personalized HTML email responses based on contact context
- Python parser extracts structured subject and body from AI output
- Automated Gmail reply sends professional formatted response
- Smart filtering only responds to known contacts, preventing spam auto-replies
Features
- Context-aware responses: Uses contact notes and history for personalization
- HTML email formatting: Professional, clean email structure
- Selective automation: Only responds to contacts in database
- Claude Sonnet 4.5 integration: Latest AI model for intelligent responses
- Structured output parsing: Reliable extraction of subject and body
- Real-time monitoring: 1-minute polling interval
Steps
1. Email Monitoring
Node: Gmail Trigger
Purpose: Monitors Gmail inbox for new incoming emails.
Configuration:
- Poll Time: Every minute
- Event: New email received
- Output: Email data including sender, subject, body
2. Contact Lookup
Node: Get row(s) (Data Table)
Purpose: Searches for sender email in Contacts database.
Configuration:
- Data Table: Contacts
- Operation: Get
- Condition: Email = sender's email address
- Must Match: All Conditions
Output: Contact record with Name, Email, Phone, Notes (if exists)
Design Decision: If contact not found, workflow stops here. Only known contacts receive automated responses to prevent spam-like behavior.
3. AI Response Generation
Node: Message a model (Claude)
Purpose: Generates personalized email response using contact context.
Configuration:
- Model: Claude Sonnet 4.5 (claude-sonnet-4-5-20250929)
- Input: Contact data + received email
User Prompt:
You are an AI assistant helping to write professional email responses.
Create a well-formatted HTML email response based on the customer information and received email.
Customer Data:
1-Name: {{ $json.Name }}
2-Notes: {{ $json.Notes }}
Received Email:
1-Email Subject: {{ $('Gmail Trigger').item.json.headers.subject }}
2-Email Body: {{ $('Gmail Trigger').item.json.text }}
CRITICAL: Your response MUST follow this EXACT format:
Subject: [Your subject line]
HTML_BODY_START
<p>Hi [Name],</p>
<p>[First paragraph with warm acknowledgment]</p>
<p>[Main content addressing their needs]</p>
<p>[Next steps or questions]</p>
<p>Best regards,<br>
Alvaro</p>
HTML_BODY_END
Rules:
- Use <p> tags for paragraphs
- Use <br> for line breaks
- Keep it clean and professional
- The HTML_BODY_START and HTML_BODY_END markers are REQUIRED
4. Response Parsing
Node: Code in Python (Beta)
Purpose: Extracts structured subject and HTML body from Claude's response.
Logic:
- Uses regex to extract Subject line
- Finds HTML content between
HTML_BODY_START and HTML_BODY_END markers
- Fallback: If no HTML found, converts plain text with
<p> and
`` tags
- Returns JSON with
subject, body, and body_type
Why needed: Gmail node requires separate subject and body fields
5. Email Delivery
Node: Send a message (Gmail)
Purpose: Sends formatted HTML email response to original sender.
Configuration:
- To: Original sender's email
- Subject: Parsed subject from Claude
- Body: Parsed HTML body
- Options: Attribution disabled for clean signature
Tools Used
- n8n: Workflow automation and orchestration
- Claude Sonnet 4.5: AI model for response generation (via Anthropic API)
- Gmail API: Email monitoring and sending
- Data Tables: Contact database storage
- Python: Response parsing and text processing
Impact
- Zero manual email responses for known contacts
- Context-aware personalization using contact history and notes
- Professional HTML formatting in all responses
- Smart filtering prevents spam auto-replies to unknown senders
- Sub-2-minute response time from email receipt to reply
- Scalable architecture can handle multiple contacts simultaneously
Learnings
- Prompt engineering for structured output: Using markers like
HTML_BODY_START ensures reliable parsing
- Edge case handling: Workflow intentionally stops for unknown contacts
- Claude integration best practices: System prompts with clear format requirements
- Python parsing in n8n: Regex patterns for extracting structured data from text
- Production-ready automation: Thoughtful design prevents unwanted auto-replies
Database Schema
Contacts Table:
- Name (string)
- Email (string) - used for lookup
- Phone_Number (string)
- Notes (string) - context for AI personalization
Sales Data Analysis Agent
This workflow also includes a conversational AI agent for analyzing sales data using natural language queries.
Architecture
Trigger: Chat interface (When chat message received)
AI Agent: Sales Data Agent with Claude Sonnet 4.5 (via OpenRouter)
Tools Available:
- All Rows - Returns complete sales dataset
- Product Name Query - Filters by product (Wireless Headphones, Bluetooth Speaker, Phone Case)
- Date Query - Filters by date (YYYY-MM-DD format)
- Product ID Query - Filters by ID (WH001, BS002, PC003)
</aside>

๐ Download & Explore the Workflow:
Smart Gmail Auto-Reply with Claude.json
View GitHub Repository:
Smart-Gmail-Auto-Reply-with-Claude-n8n/Smart Gmail Auto-Reply with Claude.json at main ยท AlvLeoAI/Smart-Gmail-Auto-Reply-with-Claude-n8n