AutomationFlowsAI & RAG › Create Ai-summarized Email Digests From Gmail Labels with Openai O4-mini

Create Ai-summarized Email Digests From Gmail Labels with Openai O4-mini

ByGerman Velibekov @germanv on n8n.io

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

Cron / scheduled trigger★★★★☆ complexityAI-powered16 nodesOpenAI ChatDocument Default Data LoaderText Splitter Recursive Character Text SplitterChain SummarizationGmail
AI & RAG Trigger: Cron / scheduled Nodes: 16 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #5839 — we link there as the canonical source.

This workflow follows the Chainsummarization → OpenAI Chat recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "Daily Email Digest with AI Summarization",
  "tags": [],
  "nodes": [
    {
      "id": "6e739c6d-8fe0-46ba-9f92-c88adff879cf",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -260,
        440
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c772f463-4fe1-4e8f-8cac-d9c1dec71f03",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{$items().length}}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "572ca84c-f3b8-478d-aa51-4d63ae462671",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        260
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "o4-mini",
          "cachedResultName": "o4-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "8f6dafea-8cf6-47d5-b117-58f748de860e",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        80,
        280
      ],
      "parameters": {
        "options": {},
        "jsonData": "={{ $json.text }}",
        "jsonMode": "expressionData",
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "ae79599f-c03c-4ca3-a074-89348c1d7d4e",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        180,
        460
      ],
      "parameters": {
        "options": {},
        "chunkSize": "={{ $json.text.length }}"
      },
      "typeVersion": 1
    },
    {
      "id": "646ced0e-cd43-449b-917c-bd376b748c15",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        40,
        660
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d7c20f5e-f388-474a-975b-413292a1ad60",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        460,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "165006bf-ec9c-4f7b-a840-28486ce1dba3",
              "name": "output.text",
              "type": "string",
              "value": "={{ $json.output.text }}"
            },
            {
              "id": "94bb7c0a-210a-484f-b363-3960cce119f2",
              "name": "subject",
              "type": "string",
              "value": "={{ $('Get mails (last 24h)').item.json.subject }}"
            },
            {
              "id": "30f4fd53-3c46-4e6c-8852-7fedb2a32301",
              "name": "headers.from",
              "type": "string",
              "value": "={{ $('If').item.json.headers.from }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7681c2c6-ccbc-4675-8f5d-9ebfe52e1788",
      "name": "Combine Subject and Body",
      "type": "n8n-nodes-base.code",
      "position": [
        680,
        240
      ],
      "parameters": {
        "jsCode": "// Combine all items into one content block\nlet allContent = '';\n\n\n\nfor (const item of $input.all()) {\n  const originalFrom = `${item.json.headers.from}`;\n  const fromPrefix = \"From: \";\n  let trancatedFrom;\n  \n  if (originalFrom.startsWith(fromPrefix)) {\n    trancatedFrom = originalFrom.substring(fromPrefix.length);\n  } else {\n    trancatedFrom = originalFrom;\n  }\n  // Create H2 heading from subject\n  const heading = `<h3>${item.json.subject} [${trancatedFrom}]</h3>`;\n  \n  // Add heading and body to combined content\n  allContent += heading + `\\n\\n${item.json.output.text}\\n\\n`;\n}\n\n// Return a single item with all combined content\nreturn [{\n  json: {\n    combinedContent: allContent.trim(),\n    itemCount: $input.all().length\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "b39f8459-49b0-47e9-8848-71d76aac8149",
      "name": "Summarization Mails",
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "position": [
        -20,
        40
      ],
      "parameters": {
        "options": {
          "summarizationMethodAndPrompts": {
            "values": {
              "prompt": "Write a concise summary of the following email digest.\n- If the digest includes multiple topics, summarize each topic as a separate bullet point.\n- If the digest refers to external links for a topic preserve them and insert at appropriated places inside summorized text under ascending numbers ([1], [2], etc.).\n- Format the output as HTML, using <p> tags for paragraphs and <ul><li> for bullet points and <a href> for external links.\n- Reply directly with the summorized text.\n\nExample:\n<ul>\\n  <li>\\n    <p>Meta has recruited Apple's head of AI models, Ruoming Pang<a href=\"https://techcrunch.com/2025/07/07/meta-reportedly-recruits-apples-head-of-ai-models/\">[1]</a>, suggesting an intensifying talent war and possible work on its next-gen AI glasses<a href=\"https://www.androidauthority.com/meta-hypernova-smart-glasses-leaked-render-3572798/\">[2]</a>.</p>\\n  </li>\\n  <li>\\n    <p>Key AI headlines: Chinese firms ramp up; Samsung forecasts a 56% profit drop amid weak AI chip demand<a href=\"https://www.cnbc.com/2025/07/08/samsung-projects-second-quarter-profits-drop-56-percent-struggles-ai-demand-nvidia-sk-YOUR_OPENAI_KEY_HERE-micron.html\">[3]</a>; Cursor blames costly models for business woes<a href=\"https://techcrunch.com/2025/07/07/cursor-apologizes-for-unclear-pricing-changes-that-upset-users/\">[4]</a>; CoreWeave to buy Core Scientific for $9 billion<a href=\"https://www.bloomberg.com/news/articles/2025-07-07/coreweave-to-buy-core-scientific-in-deal-valued-at-9-billion\">[5]</a>.\n\nDigest to summorize.\n\"{text}\"\n\nSUMMARY:",
              "summarizationMethod": "stuff"
            }
          }
        },
        "operationMode": "documentLoader"
      },
      "typeVersion": 2.1
    },
    {
      "id": "5176a79f-2d9b-43c9-a20a-819e60bda044",
      "name": "Send Digested mail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        900,
        240
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $json.combinedContent }}",
        "options": {},
        "subject": "=Daily Tech-News Digest for {{ $now.toISODate() }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "67798876-7912-4597-9959-000bf8f870af",
      "name": "Get mails (last 24h)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -480,
        440
      ],
      "parameters": {
        "limit": 20,
        "simple": false,
        "filters": {
          "labelIds": [
            "YOUR_LABEL_ID"
          ],
          "receivedAfter": "={{$now.minus({days: 1}).toISO()}}"
        },
        "options": {},
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "de4aab88-76ea-4688-8385-47406e01c2e5",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -680,
        440
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d45213a8-e076-48ac-8593-55a12ec18245",
      "name": "Main Workflow Explanation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1180,
        0
      ],
      "parameters": {
        "width": 460,
        "height": 800,
        "content": "## Daily Email Digest with AI Summarization\n### This n8n workflow automatically creates AI-powered summaries of labeled emails and sends them as a daily digest.\n\nPerfect for staying on top of newsletters, news feeds, or any categorized emails without information overload!\n\n### How it works\n* **Scheduled daily** at 9 AM to check for new emails\n* **Fetches labeled emails** from the last 24 hours using Gmail\n* **AI summarization** using OpenAI to create concise summaries\n* **Combines multiple emails** into one formatted digest\n* **Sends digest email** with all summaries in HTML format\n\n### How to set up\n* Create a Gmail label for emails you want summarized\n* Update the label ID in the 'Get mails' node\n* Configure OpenAI API credentials\n* Set your email address in the 'Send Digested mail' node\n* Adjust the schedule trigger time as needed\n\n### Requirements\n* Gmail account with OAuth2 setup\n* OpenAI API account and credentials\n* Email label configured in Gmail\n\n### Customization options\n* Change the summarization prompt for different output styles\n* Adjust the time range for email retrieval\n* Modify the digest email template\n* Add additional processing or filtering logic\n\n### Who's it for\n* Content creators who follow multiple news sources\n* Professionals managing industry newsletters\n* Anyone wanting to reduce email overwhelm\n\n### Need Help?\nJoin the [Discord](https://discord.com/invite/XPKeKXeB7d) or ask in the [Forum](https://community.n8n.io/)!\n\nHappy Automating!"
      },
      "typeVersion": 1
    },
    {
      "id": "4bfbdef6-39fd-464e-9ccf-1d1bd71e2372",
      "name": "Email Retrieval Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -700,
        580
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 300,
        "content": "## 1. Scheduled Email Retrieval\n[Read more about Schedule Trigger](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/)\n[Read more about Gmail node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.gmail/)\n\nThe workflow runs daily at 9 AM and fetches emails from a specific Gmail label received in the last 24 hours. Configure your desired label in the Gmail node to categorize which emails should be included in your digest."
      },
      "typeVersion": 1
    },
    {
      "id": "290e0ef6-60a0-4f0a-8040-31ed41a91af8",
      "name": "AI Processing Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -260
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 360,
        "content": "## 2. AI-Powered Email Summarization\n[Read more about LangChain nodes](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainSummarization/)\n\nEach email is processed through OpenAI's language model to create concise, readable summaries. The workflow:\n* Loads email content into the document processor\n* Splits text for optimal AI processing\n* Uses a custom prompt to generate HTML-formatted summaries\n* Preserves external links and formats them properly\n\nThe summarization prompt is specifically designed to create clean, scannable content with proper bullet points and link preservation."
      },
      "typeVersion": 1
    },
    {
      "id": "4a78b0ba-cdea-4da8-9929-a955eafbefa5",
      "name": "Formatting and Output Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 580,
        "height": 700,
        "content": "## 3. Content Formatting and Email Delivery\n[Read more about Code node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/)\n\nThe summarized emails are combined into a single digest:\n* **Edit Fields** extracts key data (subject, sender, summary)\n* **Combine Subject and Body** merges all summaries with proper headers\n* **Send Digested mail** delivers the final HTML-formatted digest\n\nThe final email includes organized summaries with sender information and maintains all formatting for easy reading."
      },
      "typeVersion": 1
    },
    {
      "id": "75c6d291-083b-416d-b8fa-ecfe24b875d7",
      "name": "Conditional Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        580
      ],
      "parameters": {
        "color": 7,
        "width": 280,
        "height": 200,
        "content": "## Smart Processing\n[Read more about If node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.if/)\n\nThe workflow intelligently checks if any emails were found. If no emails match the criteria, it skips processing to avoid sending empty digests."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Summarization Mails",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Combine Subject and Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get mails (last 24h)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Summarization Mails",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Summarization Mails",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Summarization Mails": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get mails (last 24h)": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Subject and Body": {
      "main": [
        [
          {
            "node": "Send Digested mail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

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

Source: https://n8n.io/workflows/5839/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow automates patient communication for medical clinics using the WhatsApp Business API. It supports appointment booking, rescheduling, service inquiries, follow-ups, and document submission

Google Sheets, Data Table, Data Table Tool +12
AI & RAG

Personalized AI Tech Newsletter Using RSS, OpenAI and Gmail. Uses splitOut, embeddingsOpenAi, documentDefaultDataLoader, textSplitterRecursiveCharacterTextSplitter. Scheduled trigger; 24 nodes.

OpenAI Embeddings, Document Default Data Loader, Text Splitter Recursive Character Text Splitter +5
AI & RAG

This n8n template automates the collection, storage, and summarization of technology news from top sites, turning it into a concise, personalized weekly newsletter.

OpenAI Embeddings, Document Default Data Loader, Text Splitter Recursive Character Text Splitter +5
AI & RAG

This workflow implements a two-stage news automation system designed for reusable and topic-driven email delivery. News articles are continuously collected from multiple platforms using RSS feeds and

OpenAI Embeddings, Document Default Data Loader, Text Splitter Recursive Character Text Splitter +5
AI & RAG

Splitout Code. Uses manualTrigger, stickyNote, documentDefaultDataLoader, lmChatOpenAi. Event-driven trigger; 18 nodes.

Document Default Data Loader, OpenAI Chat, Agent +5