DEV Community

Cover image for How to Build an AI Email Agent with n8n (Step-by-Step Advanced Guide Using Free & Open-Source Tools)
KAMAL KISHOR
KAMAL KISHOR

Posted on

How to Build an AI Email Agent with n8n (Step-by-Step Advanced Guide Using Free & Open-Source Tools)

AI email agents sound futuristic — like something out of Tony Stark’s J.A.R.V.I.S. But here’s the secret: you don’t need a PhD in AI or 5+ years of coding experience to build one.

Thanks to n8n, Mistral AI, and Milvus, you can create your own intelligent email assistant — for free. This guide will walk you step by step through setting it up.

By the end, you’ll have an agent that:
✅ Reads your contacts from a Google Doc
✅ Stores them in a free vector database (Milvus)
✅ Understands natural language commands with Mistral
✅ Sends personalized emails through Gmail

And yes — no paid AI API keys required. 🚀


🔧 Tools We’ll Use

  • n8n → No-code workflow automation (your control center)
  • Google Docs → Store your contact list
  • Milvus (or Weaviate) → Free, open-source vector database
  • Mistral → Open-source LLM for text parsing & generation
  • Gmail → To send actual emails

Step 1: Create Your Contact Database in Google Docs

  1. Open a new Google Doc.
  2. Create a simple table like this:
Name         | Email
-------------|-------------------
Kevin Levin  | kevin@example.com
Gwen Tennyson| gwen@example.com
Enter fullscreen mode Exit fullscreen mode
  1. Copy your Google Doc ID (the long string in the document URL). Example:
https://docs.google.com/document/d/THIS_PART_IS_THE_ID/edit
Enter fullscreen mode Exit fullscreen mode

We’ll use this in n8n later.


Step 2: Set Up Milvus (Vector Database)

Unlike Pinecone (paid), Milvus is free and open source. You can host it locally with Docker:

docker pull milvusdb/milvus
docker run -p 19530:19530 milvusdb/milvus
Enter fullscreen mode Exit fullscreen mode
  • Milvus will store your contacts as embeddings.
  • Install pymilvus if you want CLI control:
pip install pymilvus
Enter fullscreen mode Exit fullscreen mode

This is where your agent will later “ask” things like “Who’s Kevin?”


Step 3: Load Contacts into Milvus with n8n

Now let’s bring your Google Docs contacts into Milvus using n8n.

  1. Create a new workflow in n8n.

  2. Add a Manual Trigger node.

  3. Add a Google Docs node:

  • Authenticate with your Google Cloud credentials.
  • Action → Get Document.
  • Enter your Google Doc ID.
  1. Add a Split Text / JSON Extractor node → parse contact table into {name, email} pairs.

  2. Add an Embeddings node:

  • Model: mistral-embed (via a free Hugging Face inference API or self-hosted model).
  • Input: names/emails.
  1. Add a Milvus node:
  • Operation: Insert Vectors.
  • Collection: contacts.
  • Fields: { vector: embedding, metadata: { name, email } }.
  1. Connect:
Manual Trigger → Google Docs → Split/Parse → Embeddings → Milvus
Enter fullscreen mode Exit fullscreen mode

Run once → your contacts are now searchable in Milvus! 🎉


Step 4: Build the Email Sending Tool in n8n

Now let’s give the agent the ability to send emails.

  1. Create a new workflow in n8n.
  2. Trigger → Webhook (so the main agent workflow can call it).
  3. Add a Gmail node:
  • Connect via OAuth2 credentials.
  • Action: Send Email.
  • Fields: To, Subject, Body → all set as expressions.

Example JSON structure the agent will pass:

{
  "to": "kevin@example.com",
  "subject": "Lunch?",
  "message": "Hey Kevin, want to grab lunch tomorrow? Best, Kamal"
}
Enter fullscreen mode Exit fullscreen mode

Save this workflow as Send Email Tool.


Step 5: Assemble the AI Agent Workflow

This is where the magic happens.

  1. Create another workflow in n8n → Trigger: Webhook (Chat Command).
  2. Add an Agent Node (Advanced AI → Tools Agent).
  3. Configure system message:
You are an AI Email Assistant.
Use Milvus to find contacts.
Use the Send Email Tool to send emails.
Always sign off with "Best, [Your Name]".
Enter fullscreen mode Exit fullscreen mode
  1. Add Tools:
  • Milvus Vector Store (retrieve emails).
  • Send Email Tool (callable workflow).
  1. Add Mistral Node for natural language parsing:
  • Input: user command (e.g., "Email Kevin about lunch").
  • Output: structured JSON {to, subject, message}.
  1. Connect everything:
Webhook (Chat Input) → Mistral → Agent → (Milvus + Send Email Tool)
Enter fullscreen mode Exit fullscreen mode

Debugging & Testing

  • If Gmail errors → check OAuth consent screen.
  • If Milvus returns empty → confirm embeddings model matches.
  • If n8n errors → review Executions log for failed nodes.

🚀 What You’ve Built

✅ AI reads contact info from Google Docs
✅ Embeds and searches contacts in Milvus
✅ Parses natural commands with Mistral
✅ Sends emails via Gmail — automatically

All without writing a single line of complex backend code.


🌟 Next-Level Upgrades

  • Add Google Calendar → “Schedule lunch with Kevin tomorrow at 1 PM.”
  • Add labeling rules → auto-sort emails into categories.
  • Add memory → let your agent remember previous conversations.
  • Add multi-user mode → manage contacts & Gmail for teams.

🔑 Key Takeaway

You just built a production-ready AI Email Agent using:

  • n8n (workflow engine)
  • Google Docs (contact source)
  • Milvus (free vector DB)
  • Mistral (open-source AI brain)
  • Gmail (real email sender)

No Pinecone, no OpenAI fees — completely free and open.

When your agent sends its first email, don’t be surprised if you feel like Iron Man. 😉


Top comments (0)