Skip to main content

Email parser for RAG agent powered by Gmail and Mem0

Workflow preview

Workflow preview
100%
Email parser for RAG agent powered by Gmail and Mem0 preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow contains community nodes that are only compatible with the self hosted version of n8n. Alternatively, you can delete the community node and use the HTTP node instead. Most email agent...

Best for

  • Document Extraction automation workflows
  • Multimodal AI automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.set, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.outputparserstructured, @n8n/n8n-nodes-langchain.outputparserautofixing, n8n-nodes-base.gmailtrigger, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.lmchatmistralcloud, n8n-nodes-mcp.mcpclient

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Stephan Koning.

Original n8n.io source

1.1 Workflow description

Title
Email parser for RAG agent powered by Gmail and Mem0
Workflow name
Email parser for RAG agent powered by Gmail and Mem0

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

**Alternatively, you can delete the community node and use the HTTP node instead. ** Most email agent templates are fundamentally broken. They're stateless—they have no long-term memory. An agent that can't remember past conversations is just a glorified auto-responder, not an intelligent system.

This workflow is Part 1 of building a truly agentic system: creating the brain.

Before you can have an agent that replies intelligently, you need a knowledge base for it to draw from. This system uses a sophisticated parser to automatically read, analyze, and structure every incoming email. It then logs that intelligence into a persistent, long-term memory powered by mem0.

The Problem This Solves

Your inbox is a goldmine of client data, but it's unstructured, and manually monitoring it is a full-time job. This constant, reactive work prevents you from scaling. This workflow solves that "system problem" by creating an "always-on" engine that automatically processes, analyzes, and structures every incoming email, turning raw communication into a single source of truth for growth.


How It Works

This is an autonomous, multi-stage intelligence engine. It runs in the background, turning every new email into a valuable data asset.

  1. Real-Time Ingest & Prep: The system is kicked off by the Gmail Trigger, which constantly watches your inbox. The moment a new email arrives, the workflow fires. That email is immediately passed to the Set Target Email node, which strips it down to the essentials: the sender's address, the subject, and the core text of the message (I prefer using the plain text or HTML-as-text for reliability). While this step is optional, it's a good practice for keeping the data clean and orderly for the AI.

  2. AI Analysis (The Brain): The prepared text is fed to the core of the system: the AI Agent. This agent, powered by the LLM of your choice (e.g., GPT-4), reads and understands the email's content. It's not just reading; it's performing analysis to:

    • Extract the core message.
    • Determine the sentiment (Positive, Negative, Neutral).
    • Identify potential red flags.
    • Pull out key topics and keywords.
    • The agent uses Window Buffer Memory to recall the last 10 messages within the same conversation thread, giving it the context to provide a much smarter analysis.
  3. Quality Control (The Parser): We don't trust the AI's first draft blindly. The analysis is sent to an Auto-fixing Output Parser. If the initial output isn't in a perfect JSON format, a second Parsing LLM (e.g., Mistral) automatically corrects it. This is our "twist" that guarantees your data is always perfectly structured and reliable.

  4. Create a Permanent Client Record: This is the most critical step. The clean, structured data is sent to mem0. The analysis is now logged against the sender's email address. This moves beyond just tracking conversations; it builds a complete, historical intelligence file on every person you communicate with, creating an invaluable, long-term asset.

Optional Use: For back-filling historical data, you can disable the Gmail Trigger and temporarily connect a Gmail "Get Many" node to the Set Target Email node to process your backlog in batches.


Setup Requirements

To deploy this system, you'll need the following:

  • An active n8n instance.
  • Gmail API credentials.
  • An API key for your primary LLM (e.g., OpenAI).
  • An API key for your parsing LLM (e.g., Mistral AI).
  • An account with mem0.ai for the memory layer.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Set Target Email

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 2 - Window Buffer Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 3 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.2

Block 4 - Auto-fixing Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserAutofixing - outputParserAutofixing
Config choices
Version 1

Block 5 - Full_Email

Type / Role
n8n-nodes-base.gmailTrigger - gmailTrigger
Config choices
Version 1.2

Block 6 - llm of your choice

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 7 - Parsing LLM

Type / Role
@n8n/n8n-nodes-langchain.lmChatMistralCloud - lmChatMistralCloud
Config choices
Version 1

Block 8 - Add_Parsed email to memory

Type / Role
n8n-nodes-mcp.mcpClient - mcpClient
Config choices
Version 1

Block 9 - email to mem0

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Parse_Email Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

3. Summary Table

Workflow Email parser for RAG agent powered by Gmail and Mem0
Complexity intermediate
Nodes 11
Categories Document Extraction, Multimodal AI
Author Stephan Koning
Published 07 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7150/7150.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Email parser for RAG agent powered by Gmail and Mem0 do?

This workflow contains community nodes that are only compatible with the self hosted version of n8n. Alternatively, you can delete the community node and use the HTTP node instead. Most email agent...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Document Extraction, Multimodal AI use case.