Describe the problem/error/question
I’m using IMAP trigger node for email (zohomail) automation workflow. The workflow is active in state all round the clock. The imap trigger node is working 90% of the time but the trigger is not working sometimes in the middle. The emails are getting MARKED AS READ but they never passed through the workflow. They are neither visible in successful/failed executions nor in the error workflow logs. Let us know the exact reason why this is happening and how to prevent it?
What is the error message (if any)?
Error on powershell:
Email Read Imap: Connected closed unexpectedly
The trigger node “Email Trigger (IMAP)” of workflow “pokonut email automation” failed with the error: “Imap connection closed unexpectedly”. Will try to reactivate.
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
{
"nodes": [
{
"parameters": {
"operationMode": "nodeInputBinary",
"options": {
"binaryDataKey": "={{ $json.textPlain }}",
"summarizationMethodAndPrompts": {
"values": {
"combineMapPrompt": "=Write a concise summary of the following in max 100 words:\n\n\"{{ $json.textPlain }}\"\n\nDo not enter the total number of words used.",
"prompt": "=Write a concise summary of the following in max 100 words:\n\n\"{{ $json.textPlain }}\"\n\nDo not enter the total number of words used."
}
}
}
},
"id": "ab9f6ac3-2095-44df-aeba-2eab96ecf425",
"name": "Email Summarization Chain",
"type": "@n8n/n8n-nodes-langchain.chainSummarization",
"position": [
-288,
976
],
"typeVersion": 2
},
{
"parameters": {
"promptType": "define",
"text": "=Write the text to reply to the following email:\n{{ $('Markdown').item.json.textPlain }}\n",
"options": {
"systemMessage": "# AI Email Support System Prompt - Pokonut D2C\n\nYou are the official AI Email Support Assistant for Pokonut, an Indian D2C ecommerce brand. Your job is to draft accurate, empathetic, and professional email responses based on customer messages and the internal knowledge base stored in the Pinecone vector database.\n\n## Core Responsibilities\n\n**You can:**\n- Provide informational responses (policies, product details, shipping timelines, FAQs)\n- Answer order status queries using available data\n- Offer guidance and instructions retrieved from the knowledge base\n- Clarify processes and procedures\n\n**You cannot:**\n- Approve or execute backend actions (cancellations, refunds, address changes, mobile number changes, email changes, returns, exchanges, order modifications)\n- Make definitive commitments on behalf of the support team\n- Process any requests that require system-level changes or human verification\n\n## Action Request Handling Protocol\n\nWhen a customer requests any of the following actions, you **must escalate to human support**:\n- Order cancellations\n- Refund requests\n- Delivery address changes\n- Mobile number changes\n- Email address changes\n- Return requests\n- Exchange requests\n- Order modifications (quantity, items, variants, etc.)\n\n**Escalation Response Template:**\n```\n<p>I understand your request for [briefly state the request]. I sincerely apologize that I don't have the authority to process this directly.</p>\n<p>However, I've noted your request and will ensure it reaches the concerned team member who can assist you. They will review your case and get back to you with an update.</p>\n```\n\n## Response Requirements\n\n### Format & Structure\n- Output only the **HTML email body** (no subject line)\n- Must be **under 100 words**, **max 2 paragraphs**, **max 2 lines each**\n- Follow Gmail-safe HTML:\n - `<p>` for paragraphs\n - `<br>` for line breaks\n - `<strong>` or `<b>` for emphasis\n - `<ul><li>...</li></ul>` for lists\n - **No `\\n` or `\\n\\n`**\n\n### Email Structure\n1. **Salutation:** `<p>Namaste,</p>`\n2. **Body:** Use `<p>` tags for each paragraph or `<ul><li>...</li></ul>` for bullet lists\n3. **Contact Information (Always include):**\n ```\n <p>For further queries, please feel free to reach out to us via phone (+91-90356 75358) or via WhatsApp (63635 01207).</p>\n ```\n4. **Closing:**\n ```\n <p>Best regards,<br>Pokonut Support Team</p>\n ```\n\n### Special Rules\n- **NEVER return empty output under any circumstances**\n- **Always respond in the same language used by the customer**\n- Retrieve relevant information from the Pinecone vector database before responding\n- Do NOT mention definite timeframes unless explicitly retrieved from the knowledge base\n\n### Order-Related Inquiries\n- If order number/AWB number is mentioned: include **\"Thanks for sharing the order number/AWB number.\"**\n- If missing: include **\"Here's the tracking url: https://tracking.pokonut.xyz/. If you don't find tracking status of your order, Please share the order number or AWB number so we can assist you better.\"**\n\n## Tone & Style\n\nMaintain a tone that is:\n- **Professional** - Represent the brand with care and competence\n- **Empathetic** - Acknowledge customer concerns and emotions\n- **Apologetic (when escalating)** - Express sincere regret for not being able to help directly\n- **Reassuring** - Build confidence that their issue will be resolved\n- **Warm** - Culturally appropriate for Indian customers\n- **Clear** - Easy to understand, no jargon\n\n## Examples\n\n### ❌ Incorrect Response (Approving Action Without Authority)\n**User Query:** \"Cancel my order #12345\"\n\n**Wrong AI Response:**\n```\n<p>Namaste,</p>\n<p>Your order #12345 has been cancelled successfully. You will receive a refund in 5-7 business days.</p>\n```\n\n### ✅ Correct Response (Escalation)\n**User Query:** \"Cancel my order #12345\"\n\n**Correct AI Response:**\n```\n<p>Namaste,</p>\n<p>Thanks for sharing the order number. I understand you'd like to cancel order #12345. I sincerely apologize that I don't have the authority to process cancellations directly.</p>\n<p>However, I've noted your request and will ensure it reaches our cancellation team who can assist you promptly. Alternatively, you can reach out directly via phone (+91-90356 75358) or WhatsApp (63635 01207) for immediate assistance.</p>\n<p>For further queries, please feel free to reach out to us via phone (+91-90356 75358) or via WhatsApp (63635 01207).</p>\n<p>Best regards,<br>Pokonut Support Team</p>\n```\n\n### ✅ Correct Response (Informational Query)\n**User Query:** \"What is your return policy?\"\n\n**Correct AI Response:**\n```\n<p>Namaste,</p>\n<p>We accept returns within 7 days of delivery for unused products in original packaging. Simply initiate a return request and our team will guide you through the process.</p>\n<p>For further queries, please feel free to reach out to us via phone (+91-90356 75358) or via WhatsApp (63635 01207).</p>\n<p>Best regards,<br>Pokonut Support Team</p>\n```\n\n---\n\n**Remember:** Your role is to inform, guide, and reassure—but always escalate actions that require human verification or backend changes."
}
},
"id": "86b7c3d0-e1f2-4e2f-b293-8042700d6816",
"name": "Write email",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
96,
976
],
"typeVersion": 1.7
},
{
"parameters": {
"content": "Chain that summarizes the received email",
"height": 240,
"width": 320
},
"id": "5b36a295-fda6-4174-9078-0a8ec57620d2",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1040,
912
],
"typeVersion": 1
},
{
"parameters": {
"content": "Agent that retrieves business information from a vector database and processes the response",
"height": 240,
"width": 340
},
"id": "7110fe1f-0099-49aa-9095-96e733aa468f",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-688,
912
],
"typeVersion": 1
},
{
"parameters": {
"content": "Convert email to Markdown format for better understanding of LLM models",
"height": 240
},
"id": "e2bdbd64-3c37-4867-ae2c-0f6937d82b81",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1296,
912
],
"typeVersion": 1
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "35d7c303-42f4-4dd1-b41e-6eb087c23c3d",
"name": "email",
"type": "string",
"value": "={{ $json.output }}"
}
]
},
"options": {}
},
"id": "33bbedeb-129a-4e99-ab5a-9e0ec4456156",
"name": "Set Email text",
"type": "n8n-nodes-base.set",
"position": [
448,
976
],
"typeVersion": 3.4
},
{
"parameters": {
"modelName": "models/gemma-3-4b-it",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"typeVersion": 1,
"position": [
-240,
1264
],
"id": "a51195cf-f3cf-4de0-af1e-05ae9506e3a6",
"name": "Google Gemini Chat Model",
"credentials": {
"googlePalmApi": {
"id": "fdzsfExfs8GAkFQS",
"name": "Google Gemini(PaLM) Api account"
}
}
},
{
"parameters": {
"mailbox": "n8n_seen",
"options": {
"customEmailConfig": "=[[\"UNSEEN\"],[\"SINCE\", \"{{$today.format('yyyy-LL-dd')}}\"], [\"FROM\", [\"@gmail.com\", \"@hotmail.com\", \"@zohomail.com\"]]]",
"forceReconnect": 1,
"trackLastMessageId": true
}
},
"type": "n8n-nodes-base.emailReadImap",
"typeVersion": 2.1,
"position": [
-1232,
1024
],
"id": "7945a5f0-ded0-4f58-befd-a62db5a85743",
"name": "Email Trigger (IMAP)",
"credentials": {
"imap": {
"id": "CSfxDMqO9z26gb4e",
"name": "IMAP account"
}
}
},
{
"parameters": {
"options": {}
},
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 3,
"position": [
-960,
1024
],
"id": "7b159910-f161-4701-9903-4cf57f25a7c6",
"name": "Loop Over Items"
},
{
"parameters": {
"mode": "retrieve-as-tool",
"toolDescription": "Extract the chunks relevant to the search query to generate appropriate response",
"pineconeIndex": {
"__rl": true,
"value": "index3",
"mode": "list",
"cachedResultName": "index3"
},
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
"typeVersion": 1.3,
"position": [
208,
1216
],
"id": "be6e414e-3d48-4fda-805a-2632d2e2bdc5",
"name": "Pinecone Vector Store",
"credentials": {
"pineconeApi": {
"id": "7uLhBydKC5olrAc0",
"name": "PineconeApi account"
}
}
},
{
"parameters": {},
"type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
"typeVersion": 1,
"position": [
288,
1360
],
"id": "c785ca99-d50f-4d46-9f88-d8c183a9fb9c",
"name": "Embeddings Google Gemini",
"credentials": {
"googlePalmApi": {
"id": "fdzsfExfs8GAkFQS",
"name": "Google Gemini(PaLM) Api account"
}
}
},
{
"parameters": {
"html": "={{ $json.textHtml }}",
"options": {}
},
"id": "42d150d8-d574-49f9-9c0e-71a2cdea3b79",
"name": "Markdown",
"type": "n8n-nodes-base.markdown",
"position": [
-544,
992
],
"typeVersion": 1
},
{
"parameters": {
"content": "Production running workflow",
"height": 720,
"width": 2608,
"color": 4
},
"type": "n8n-nodes-base.stickyNote",
"position": [
-1328,
816
],
"typeVersion": 1,
"id": "dc51c214-b03d-403c-9dfb-6d13944f1f4e",
"name": "Sticky Note3"
},
{
"parameters": {
"dataTableId": {
"__rl": true,
"value": "cUt9pLCrDrIS1dCg",
"mode": "list",
"cachedResultName": "email_automation_production_data",
"cachedResultUrl": "/projects/xe2hT3MxlY19Xboe/datatables/cUt9pLCrDrIS1dCg"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"from": "={{ $('Email Trigger (IMAP)').item.json.from }}",
"date": "={{ $('Email Trigger (IMAP)').item.json.date }}",
"subject": "={{ $('Email Trigger (IMAP)').item.json.subject }}",
"text_plain": "={{ $('Email Trigger (IMAP)').item.json.textPlain }}",
"email": "= {{ $('Set Email text').item.json.email }}",
"sent_to": "={{ $json.accepted[0] }}"
},
"matchingColumns": [],
"schema": [
{
"id": "from",
"displayName": "from",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"readOnly": false,
"removed": false
},
{
"id": "date",
"displayName": "date",
"required": false,
"defaultMatch": false,
"display": true,
"type": "dateTime",
"readOnly": false,
"removed": false
},
{
"id": "subject",
"displayName": "subject",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"readOnly": false,
"removed": false
},
{
"id": "text_plain",
"displayName": "text_plain",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"readOnly": false,
"removed": false
},
{
"id": "email",
"displayName": "email",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"readOnly": false,
"removed": false
},
{
"id": "sent_to",
"displayName": "sent_to",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"readOnly": false,
"removed": false
}
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {}
},
"type": "n8n-nodes-base.dataTable",
"typeVersion": 1,
"position": [
992,
976
],
"id": "63be7e8f-f9a4-48b6-9a20-b83369cb5e39",
"name": "Insert row"
},
{
"parameters": {
"amount": 30
},
"type": "n8n-nodes-base.wait",
"typeVersion": 1.1,
"position": [
1200,
976
],
"id": "e9cf909f-9bbb-45cd-a10f-2ced17e4d8ed",
"name": "Wait",
"webhookId": "fe9537b7-2e1a-4b97-af7a-e6727941deaf"
},
{
"parameters": {
"fromEmail": "[email protected]",
"toEmail": "={{ $('Email Trigger (IMAP)').item.json.from }}",
"emailFormat": "html",
"html": "={{ $json.email }}",
"options": {
"replyTo": "={{ $('Email Trigger (IMAP)').item.json.from }}"
},
"customHeadersUi": {
"headers": [
{
"name": "In-Reply-To",
"value": "={{ $('Email Trigger (IMAP)').item.json.metadata['message-id'] }}"
}
]
}
},
"type": "n8n-nodes-better-send-mail.betterEmailSend",
"typeVersion": 2,
"position": [
656,
976
],
"id": "d99ac8dd-80b6-45e4-b6b2-64f6ac4dd650",
"name": "Send email1",
"webhookId": "6040827f-8d59-4cac-87d3-cf19ebefbf19",
"credentials": {
"smtp": {
"id": "9M1gNaOVB7Mj8KAJ",
"name": "SMTP account"
}
}
},
{
"parameters": {
"model": "openai/gpt-oss-20b",
"options": {
"maxTokensToSample": 2000
}
},
"type": "@n8n/n8n-nodes-langchain.lmChatGroq",
"typeVersion": 1,
"position": [
-32,
1280
],
"id": "dbdf6b7b-67da-4637-aecf-0acdb43e883f",
"name": "Groq Chat Model",
"credentials": {
"groqApi": {
"id": "k2mUIy4dGzZzqEqH",
"name": "Groq account"
}
}
}
],
"connections": {
"Email Summarization Chain": {
"main": [
[
{
"node": "Write email",
"type": "main",
"index": 0
}
]
]
},
"Write email": {
"main": [
[
{
"node": "Set Email text",
"type": "main",
"index": 0
}
]
]
},
"Set Email text": {
"main": [
[
{
"node": "Send email1",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[]
]
},
"Email Trigger (IMAP)": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Markdown",
"type": "main",
"index": 0
}
]
]
},
"Pinecone Vector Store": {
"ai_tool": [
[
{
"node": "Write email",
"type": "ai_tool",
"index": 0
}
]
]
},
"Embeddings Google Gemini": {
"ai_embedding": [
[
{
"node": "Pinecone Vector Store",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Markdown": {
"main": [
[
{
"node": "Email Summarization Chain",
"type": "main",
"index": 0
}
]
]
},
"Insert row": {
"main": [
[
{
"node": "Wait",
"type": "main",
"index": 0
}
]
]
},
"Wait": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Send email1": {
"main": [
[
{
"node": "Insert row",
"type": "main",
"index": 0
}
]
]
},
"Groq Chat Model": {
"ai_languageModel": [
[
{
"node": "Write email",
"type": "ai_languageModel",
"index": 0
},
{
"node": "Email Summarization Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateId": "2907",
"templateCredsSetupCompleted": true,
"instanceId": "150cf44fa20f7d399bbe11903ecf05ac34c583e489a9b735e17a6d8ba185d0ee"
}
}
Share the output returned by the last node
Information on your n8n setup
- n8n version: 1.120.4
- Database (default: SQLite): SQLite
- n8n EXECUTIONS_PROCESS setting (default: own, main): default
- Running n8n via (Docker, npm, n8n cloud, desktop app): docker desktop
- Operating system: windows