FlowKit

n8n template · AI Inbox Pack

Sort your emails automatically with AI in n8n (IMAP)

This n8n workflow plugs a language model straight into your IMAP mailbox: every incoming email is read, classified into one of four categories and routed accordingly — Slack alert for urgent ones, Supabase logging for everything.

Pipelinetri-emails-ia-imap.json · 9 nodes
  1. Email entrant (IMAP)triggerEmail (IMAP)
  2. Préparer l'emailSet (fields)
  3. Classifier l'emailLLM chain
  4. Router par catégorieSwitch (routing)
  5. Alerte Slack urgentSlack
  6. FusionNo-op
  7. Journaliser dans SupabaseSupabase

Attached AI sub-nodes

  • Modèle OpenAIOpenAI model
  • Format de sortieStructured output

The problem it solves

A professional mailbox receives 50 to 150 emails a day, and only a minority deserves immediate reading. Classic filtering rules (sender, keywords) are quickly outmatched: they understand neither context nor intent, and let the essential through while archiving the trivial.

An LLM reads the email the way you would: it tells a customer complaint from an alarmist newsletter, and an invoice reminder from inbound prospecting. This template puts that reading into production in n8n, no code required, for a few cents a day.

How the workflow works, node by node

Node names are in French, exactly as they appear in the imported workflow — the logic is language-agnostic.

  1. 01

    Email entrant (IMAP)

    Email (IMAP)

    Connects to your mailbox over IMAP (Gmail, Outlook, OVH…) and triggers the workflow for every new email in INBOX. Works with any provider, unlike proprietary triggers.

  2. 02

    Préparer l'email

    Set (fields)

    Keeps only the useful fields (subject, sender, body truncated to 4,000 characters) to control token cost and avoid sending attachments to the model.

  3. 03

    Classifier l'email

    LLM chain

    The LLM chain applies a classification prompt: four categories (urgent, client, admin, newsletter), a one-sentence summary and an important-sender flag.

  4. 04

    Modèle OpenAI

    OpenAI model

    Model sub-node wired to the chain via ai_languageModel. Set to gpt-4o-mini, more than enough for classification and very cheap.

  5. 05

    Format de sortie

    Structured output

    Forces the model to answer in a strict JSON schema (category enum, summary, boolean flag): the rest of the workflow can rely on it without fragile parsing.

  6. 06

    Router par catégorie

    Switch (routing)

    Routes each email to the output matching its category. This is where you add a fifth category or change a branch's destination.

  7. 07

    Alerte Slack urgent

    Slack

    For the 'urgent' branch only: posts an alert to your channel with sender, subject and summary, for real-time reaction.

  8. 08

    Fusion

    No-op

    Convergence point of the four branches: whatever path was taken, the email continues to logging.

  9. 09

    Journaliser dans Supabase

    Supabase

    Inserts one row per processed email (subject, sender, category, summary, timestamp) into the emails_tries table: a queryable history and free flow statistics.

What you need to run it

  • n8n ≥ 1.60 (cloud or self-hosted), LangChain nodes included
  • IMAP access to your mailbox (port 993, app password recommended)
  • An OpenAI API key
  • A Slack bot with the chat:write scope
  • A free Supabase project with the emails_tries table (SQL provided in the pack guide)

Customization ideas

  • Replace the four categories with your own: the prompt, output schema and Switch must stay aligned
  • Add an 'invoice' branch pushing accounting documents to Google Drive or your management tool
  • Swap the model for Claude or a local model (Ollama) by replacing the model sub-node

FAQ

Frequently asked questions

How do I import this template into n8n?

In n8n, open Workflows then 'Import from File' and select the tri-emails-ia-imap.json file from the AI Inbox Pack. Just pick your credentials (IMAP, OpenAI, Slack, Supabase) on the flagged nodes, then activate the workflow. Node names are in French, exactly as documented here.

Does it work with Gmail or Outlook?

Yes: both expose IMAP. For Gmail, create an app password (two-step verification required); for Outlook/Microsoft 365, check that IMAP is enabled in the account settings.

What does classification cost in OpenAI API usage?

With gpt-4o-mini and emails truncated to 4,000 characters, expect roughly €0.01–0.03 per 100 emails. The cost is marginal compared to the sorting time saved.