Self-hosted AI email assistant on Linux (n8n + Ollama)
What they built
A full guide to an email assistant that reads, categorizes, drafts replies, extracts action items and routes messages, without sending email content to any external AI service.
n8n polls the mailbox and orchestrates; Ollama does classification, summarization and drafting on infrastructure you control.
Setup
- n8n via Docker Compose (or native with systemd)
- Ollama with llama3.1:8b
- Any IMAP/SMTP server (Postfix/Dovecot, Exchange, Gmail…)
How it works
- IMAP trigger every 2 minutes
- A code node cleans the body and truncates it to 2,000 chars
- Ollama classifies into support, sales, billing, spam, internal or newsletter at temperature 0
- A switch node forwards or files the email
- Separate workflows draft replies and extract action items as JSON
Results & numbers
- 3-8 s per email; 500 emails/day is about 67 minutes of processing
- 85-95% classification accuracy with an 8B model; few-shot examples push it above 90%
Gotchas
- Prompt injection via email can manipulate classification or drafts
- Never log full email bodies
- Process sequentially; Ollama handles one request at a time best
Do it yourself
- Install n8n (Docker) with extra_hosts so it reaches Ollama on the host
- Pull llama3.1:8b
- Build IMAP trigger → clean body → Ollama classify → Switch
- Add a draft-reply workflow that saves drafts only
- Configure an error workflow that moves failures to a 'processing-failed' folder
Classify this email into exactly one category: support, sales, billing, spam, internal, newsletter.
From: {{ $json.from }}
Subject: {{ $json.subject }}
Body: {{ $json.body }}
Respond with only the category name, nothing else.Related
Home RAG assistant for embedded-systems docs on Proxmox
Ollama, llama.cpp, Open WebUI, BGE-M3 and SearXNG in a GPU-passthrough VM. Moving from 6 GB to 16 GB of VRAM changed which models could run.
Self-hosted bookmarks that tag themselves with local AI (Karakeep)
Karakeep (formerly Hoarder) runs on a Debian LXC, and gemma3:4b in Ollama tags each bookmark. Getting reliable tags from a small model takes one key setting.
Paperless AI on an 8 GB RTX 3060 Ti shared with Frigate
Gemma 3 4B with embeddinggemma answers over 1,318 documents in about 5 seconds, on a GPU that's also running Frigate and Plex.
Hybrid workflow: local for private and repetitive, cloud for hard
A Linux sysadmin stopped trying to replace cloud LLMs. Ollama now handles private docs, overnight article summaries and VS Code autocomplete.