image 36

Build Your First AI Email Assistant in n8n

The Inbox That Ate My Saturday

I once knew a founder who spent every Sunday night in “email jail.” You know the routine: 200 unread messages, a mix of urgent client fires, boring newsletters, and random sales pitches. He’d sit there, a digital janitor with a mop, trying to figure out what mattered. It was soul-crushing. He wasn’t building his business; he was managing a notification firehose.

This is manual labor in a world of automation. You’re being paid to be a human filter, a low-value intern for your own attention. This stops today. We’re going to build a digital employee that lives inside your inbox, reads your mail for you, and only bothers you with the good stuff.

Why This Matters: Reclaim Your Focus

Every email is an interruption. A context switch. Your brain is like a high-performance engine; it doesn’t like stopping and starting every five minutes. This automation is about building a bouncer for your attention.

What it replaces:

  • The part-time intern who sorts mail.
  • Your own ‘check-email-while-coffee-brews’ procrastination.
  • The anxiety of ‘what if I miss something important?’

We’re not just saving time; we’re building a system that scales with you. Whether you get 10 emails a day or 1,000, this system works the same. It’s the first step toward a fully autonomous executive assistant.

What This Tool / Workflow Actually Is

We’re using a tool called n8n. Think of n8n as a visual factory floor. You’re not writing code from scratch; you’re connecting boxes on a screen with wires. Each box is a task: ‘read an email,’ ‘analyze the text,’ ‘draft a reply,’ ‘send it.’ It’s a logic pipeline.

What this does: It triggers on a new email, uses an AI to classify it (e.g., Urgent, Newsletter, Inquiry), and drafts an appropriate response. It will NOT hit ‘send’ without your approval, unless you tell it to. We’re building a helpful assistant, not a rogue robot.

Prerequisites

Zero coding skills required. If you can drag a file into a folder, you can build this. Here’s what you need:

  • An n8n account (Cloud or self-hosted).
  • An email account that supports IMAP (Gmail, Outlook, etc.). For Gmail, you’ll need an App Password.
  • An OpenAI API key (or another LLM provider).

Don’t worry, we’ll go slow. This is like assembling a Lego set with very clear instructions.

Step-by-Step Tutorial: Building the Email Sorter

Let’s head to the factory floor. Open your n8n workspace.

Step 1: The Trigger (The Mailroom Bell)

First, we need to know when we have mail. We don’t want to constantly check; we want the mailroom to ring a bell.

  1. Click the big + Add first workflow button.
  2. Search for IMAP Email and select it as your Trigger node.
  3. Double-click the node to configure it.
  4. Enter your email settings (Host, Port, User, Password). For Gmail, use an App Password.
  5. Set Trigger: On New Mail (polling interval) to something like every 1 minute.
  6. Click Test step to make sure it can connect. It should fetch a recent email.
Step 2: The AI Classifier (Your Smart Intern)

Now that we have the email, we need someone to read it and tell us what it is. That’s our AI.

  1. Click the + button to add a new node.
  2. Search for Basic LLM Chain. This is our connector to an AI model.
  3. Connect it to the IMAP node. Drag a wire from the IMAP’s right-side dot to the LLM Chain’s left-side dot.
  4. Double-click the LLM Chain node. Under ‘Model,’ select OpenAI Chat Model and connect your API key.
  5. Now we need to tell it what to do. Click the Prompt (Text) field. We’re going to write a simple instruction. This is our prompt engineering.
Step 3: The Prompt (The Job Description)

In the Prompt field, type something like this. You can copy-paste this directly:

You are an expert executive assistant. Your job is to classify incoming emails and draft a brief, helpful reply. 

Analyze the following email:
Subject: {{ $('IMAP Email').item.json.subject }}
From: {{ $('IMAP Email').item.json.fromText }}
Body: {{ $('IMAP Email').item.json.text }}

Return a JSON object with two keys:
1. "category": Choose ONE of: "Urgent", "News", "Promotion", "Inquiry".
2. "draft_reply": A 1-2 sentence professional response appropriate for the category. If the category is "Promotion", the reply should decline politely. If "Urgent", acknowledge receipt and say you'll respond shortly.
Step 4: The Code Node (Reading the Report)

The AI will give us a text response. We need to parse that into usable data to make decisions.

  1. Add a new node: Code.
  2. Connect it after the LLM Chain.
  3. Paste the following JavaScript code into the code field. This is a simple parser:
// n8n gives us the AI's text response in the first item
const aiResponseText = items[0].json.text;

let parsedResult;

try {
  // Try to find the JSON object in the text response
  const jsonMatch = aiResponseText.match(/{[\s\S]*}/);
  if (jsonMatch) {
    parsedResult = JSON.parse(jsonMatch[0]);
  } else {
    // If it's just plain text, handle it
    parsedResult = { category: 'Unclear', draft_reply: aiResponseText };
  }
} catch (error) {
  parsedResult = { category: 'Error', draft_reply: 'Could not parse AI response.' };
}

// Return the new item for the next step in the workflow
return [{
  json: {
    original_email: items[0].json,
    category: parsedResult.category,
    draft_reply: parsedResult.draft_reply
  }
}];
Step 5: The Action (The Filter)

Now we decide what to do. We'll use an If node to route the email.

  1. Add a new node: If.
  2. Connect it after the Code node.
  3. Configure the rule: Condition "String" > "Category" (from our Code node) > "Equals" > "Urgent".
  4. In the 'true' path, add a Send Email node to notify YOU immediately (e.g., send an email to your phone number's SMS gateway).
  5. In the 'false' path, you could add another If node to handle other categories, or simply add a Post to Slack or Append to CSV node to log it.
Complete Automation Example

Here is how the whole workflow looks when connected:

IMAP Email (checks every 2 mins) → Basic LLM Chain (Classifies & Drafts) → Code (Parses JSON) → If (Is it Urgent?)

  • Path True:Send Email to Me (Body: "URGENT: Subject. AI Draft: ...")
  • Path False:Append to Google Sheets (Log the email, subject, category, and draft reply for later review).

Result? You only get pinged for the real fires. Everything else is neatly organized in a spreadsheet for your weekly review. You just turned 2 hours of chaos into a 15-minute scan of a spreadsheet.

Real Business Use Cases
  1. The Solo Consultant: Gets inquiries via email. This workflow auto-drafts a response asking for their project scope and budget, adding them to a Google Sheet CRM. Consultant only responds to qualified leads.
  2. The E-commerce Store: Categorizes emails into 'Order Issue,' 'Shipping Question,' 'Return.' It drafts empathetic replies for non-urgent ones and creates a high-priority ticket for 'Order Issues' in their helpdesk.
  3. The Real Estate Agent: Filters out listing alerts and Zillow junk. It prioritizes emails from specific domains (like 'mls.com') and drafts a reply offering to schedule a showing.
  4. The Content Creator: Sorts collaboration pitches vs. fan mail. It drafts polite 'no's for low-effort pitches and flags the high-value ones for their manager to review.
  5. The Recruiter: Scans incoming applications. If the body contains keywords like 'Python' and 'Senior,' it drafts a reply requesting a portfolio link. If not, it logs it as a 'Pass.'
Common Mistakes & Gotchas
  • The Infinite Loop: If you configure your 'Send Email' node to send from the same account you are polling, you'll create a feedback loop where the bot emails itself, reads its own email, and emails itself again until n8n cuts you off. Fix: Use a different email for outbound notifications.
  • Bad Prompts: If your AI drafts weird replies, your prompt is too vague. Be specific. Give it examples. Tell it the tone to use.
  • Costs: Every email processed costs a fraction of a cent in API fees. It's cheap, but if you get 10,000 newsletters a day, it adds up. Filter those out at the IMAP level if possible.
How This Fits Into a Bigger Automation System

This workflow is the 'front door' of your business operations. It's your receptionist. Next, we can connect this to your 'archive' and 'action' departments:

  • CRM Integration: Instead of just appending to a sheet, use the data from the Code node to create a new Lead in HubSpot or Salesforce via their API nodes.
  • Voice Agents: Imagine this workflow identifies an 'Urgent' call request. It could trigger a Voice AI node to call your phone and say, "Hey, you have an urgent email from X. Want me to read it to you?"
  • RAG Systems: The 'draft_reply' is basic. You could feed the email context into a Vector Database (like Pinecone) to find similar past emails and their best solutions, making the draft much smarter.
What to Learn Next

You've just built the brain for your email inbox. You've taken a raw data stream (an inbox) and applied logic and intelligence to it. That is the essence of automation.

In our next lesson, we're going to take this a step further. We're going to build a Multi-Agent Workflow. Instead of one AI assistant, we'll build a 'Swarm' where one AI reads the email, a second AI acts as a 'Senior Manager' to approve the draft, and a third AI sends it.

You're not just learning tools. You're building a company of digital employees. See you in the next lesson.

",
"seo_tags": "AI automation, n8n tutorial, email automation, workflow automation, business productivity, OpenAI",
"suggested_category": "AI Automation Courses

Leave a Comment

Your email address will not be published. Required fields are marked *