Use this powerful n8n workflow to capture new IMAP emails, automatically clean and standardize the content, prevent duplicates using PostgreSQL, and save everything neatly into Notion. Get immediate Telegram notifications upon success.
Download this n8n workflow template and start using it instantly.
This sophisticated n8n workflow solves the critical issue of data duplication and inconsistency when using email in conjunction with a knowledge management system like Notion. Utilizing the IMAP n8n trigger, the flow continuously monitors a designated inbox (ideal for newsletters, alerts, or forwarded content). Data standardization is performed by a custom Code n8n node, which cleans HTML, extracts crucial metadata, and generates unique identifiers. Before committing resources to Notion, the workflow employs PostgreSQL to quickly check if the item has been processed before, ensuring efficiency. This complete n8n automation provides a reliable, indexed knowledge base system.
This n8n workflow operates on a scheduled polling basis using the IMAP n8n trigger to initiate the process.
messageId for reliable deduplication, using a fallback hash mechanism if the original email headers are insufficient.emailkbindex table, checking for the existence of the newly calculated messageId.exists flag returned from Postgres is false (meaning it is a truly new email).messageId and Notion page ID into the emailkbindex table to finalize the deduplication record.)To deploy this advanced n8n workflow, follow these steps:
CREATE TABLE IF NOT EXISTS emailkbindex (
messageid TEXT PRIMARY KEY,
slug TEXT,
createdat TIMESTAMPTZ NOT NULL DEFAULT now(),
notionpageid TEXT
); Email Trigger (IMAP):
Function: Serves as the continuous n8n trigger, periodically fetching new email messages that meet the UNSEEN criteria.
Key Configuration: Operation: Read Emails. Options: customEmailConfig: ["UNSEEN"].
Code:
Function: A powerful custom n8n node that standardizes raw email inputs. It ensures robust multi-format parsing (HTML to text, various date/subject fields), generates URL-safe slugs, limits text lengths for Notion summaries, and creates a highly reliable messageId for global deduplication.
Key Configuration: Contains extensive JavaScript logic for data hygiene and hash generation.
Execute a SQL query (Postgres):
Function: Executes the core deduplication logic by querying the emailkbindex table to check if the extracted messageId has been indexed previously.
Key Configuration: Query: SELECT EXISTS(...) WHERE message_id = '{{ $json.messageId }}'.
If:
Function: Controls the subsequent flow execution. It acts as a gate, allowing only unique, unprocessed emails to proceed to the archiving stage.
Key Configuration: Condition checks the result of the prior n8n node: Left ={{ $json.exists }} equals false.
Create a database page (Notion):
Function: Archives the cleaned and verified email content as a new structured page within the Notion knowledge database.
Key Configuration: Maps fields like title, snippet, sentAt, fromAddress, and sourceUrl to specific Notion database properties.
Send a text message (Telegram):
* Function: Provides instant confirmation via Telegram whenever this n8n workflow successfully processes and archives a unique email.
Use this powerful n8n workflow to automatically parse, analyze, and structure incoming Gmail messages using LLMs (GPT/Mistral). Turn unstructured email data into a Mem0 RAG knowledge base asset. Explore more n8n templates today.

Use this efficient n8n workflow to automate daily sales outreach. It reads new leads from Google Sheets, filters untouched entries, sends personalized emails via Outlook, and ensures leads are marked as contacted to prevent duplicates. An essential n8n template for sales teams.

Use this powerful n8n workflow to automate lead qualification. It captures data from an n8n form, utilizes OpenAI for drafting follow-up emails, implements a crucial human approval step via Gmail, and logs all results to Airtable.

Automate book recommendations using this advanced n8n workflow. It leverages the Ollama LLM to analyze email requests, finds relevant titles via OpenLibrary, and sends personalized recommendation emails.

Use of Mistral AI agents within this advanced n8n workflow to automatically convert actionable emails from Gmail and Outlook into structured tasks in Google Tasks or Microsoft To Do, maximizing productivity.









































