Very simple Human in the loop system email with AI e IMAP

Automate your email response process with human oversight and AI assistance using this Very simple Human in the loop system email with AI e IMAP workflow. This n8n workflow monitors your IMAP inbox for incoming emails, then leverages OpenAI to intelligently summarize the email content and draft a preliminary response. The workflow begins with an Email Trigger (IMAP) node that fetches new emails, passing their content to a Markdown node for initial processing before an Email Summarization Chain (AI:chainSummarization) powered by OpenAI (AI:lmChatOpenAi) distills the key information. An AI:agent node then uses this summary to Write email, generating a draft response. This draft is then sent to a human for review via an Approve Email (emailSend) node. Once approved, the final email is dispatched using the Send Email node. This system is ideal for marketing teams, customer support, or any business needing to efficiently manage incoming communications while ensuring quality and brand voice through human review. It significantly reduces the time spent on drafting routine email responses, allowing teams to focus on more complex tasks and ensuring timely, well-crafted communication without the overhead of constant manual intervention.

16 nodesmanual trigger92 views0 copiesMarketing
OpenAI

Workflow JSON

{"id": "Nvn78tMRNnKji7Fg", "meta": {"instanceId": "a4bfc93e975ca233ac45ed7c9227d84cf5a2329310525917adaf3312e10d5462", "templateCredsSetupCompleted": true}, "name": "Very simple Human in the loop system email with AI e IMAP", "tags": [], "nodes": [{"id": "271bb16f-9b62-41d9-ab76-114cd7ba915a", "name": "Email Trigger (IMAP)", "type": "n8n-nodes-base.emailReadImap", "position": [-1300, 1340], "parameters": {"options": {}}, "credentials": {"imap": {"id": "", "name": "[Your imap]"}}, "typeVersion": 2}, {"id": "42d150d8-d574-49f9-9c0e-71a2cdea3b79", "name": "Markdown", "type": "n8n-nodes-base.markdown", "position": [-1040, 1340], "parameters": {"html": "={{ $json.textHtml }}", "options": {}}, "typeVersion": 1}, {"id": "e9498a60-0078-4581-b269-7ff552f4047a", "name": "Send Email", "type": "n8n-nodes-base.emailSend", "position": [920, 1320], "webhookId": "a79ae1b4-648c-4cb4-b6cd-04ea3c1d9314", "parameters": {"html": "={{ $('Set Email text').item.json.email }}", "options": {}, "subject": "=Re: {{ $('Email Trigger (IMAP)').item.json.subject }}", "toEmail": "={{ $('Email Trigger (IMAP)').item.json.from }}", "fromEmail": "={{ $('Email Trigger (IMAP)').item.json.to }}"}, "credentials": {"smtp": {"id": "", "name": "[Your smtp]"}}, "typeVersion": 2.1}, {"id": "ab9f6ac3-2095-44df-aeba-2eab96ecf425", "name": "Email Summarization Chain", "type": "@n8n/n8n-nodes-langchain.chainSummarization", "position": [-780, 1340], "parameters": {"options": {"binaryDataKey": "={{ $json.data }}", "summarizationMethodAndPrompts": {"values": {"prompt": "=Write a concise summary of the following in max 100 words:\n\n\"{{ $json.data }}\"\n\nDo not enter the total number of words used.", "combineMapPrompt": "=Write a concise summary of the following in max 100 words:\n\n\"{{ $json.data }}\"\n\nDo not enter the total number of words used."}}}, "operationMode": "nodeInputBinary"}, "typeVersion": 2}, {"id": "86b7c3d0-e1f2-4e2f-b293-8042700d6816", "name": "Write email", "type": "@n8n/n8n-nodes-langchain.agent", "position": [-340, 1340], "parameters": {"text": "=Write the text to reply to the following email:\n\n{{ $json.response.text }}", "options": {"systemMessage": "You are an expert at answering emails. You need to answer them professionally based on the information you have. This is a business email. Be concise and never exceed 100 words. Only the body of the email, not create the subject"}, "promptType": "define", "hasOutputParser": true}, "typeVersion": 1.7}, {"id": "5d5a397f-f9c3-4691-afd0-9a6102679eac", "name": "OpenAI", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [-400, 1560], "parameters": {"model": {"__rl": true, "mode": "list", "value": "gpt-4o-mini", "cachedResultName": "gpt-4o-mini"}, "options": {}}, "credentials": {"openAiApi": {"id": "", "name": "[Your openAiApi]"}}, "typeVersion": 1.2}, {"id": "5b36a295-fda6-4174-9078-0a8ec57620d2", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "position": [-800, 1260], "parameters": {"width": 320, "height": 240, "content": "Chain that summarizes the received email"}, "typeVersion": 1}, {"id": "7110fe1f-0099-49aa-9095-96e733aa468f", "name": "Sticky Note5", "type": "n8n-nodes-base.stickyNote", "position": [-360, 1260], "parameters": {"width": 340, "height": 240, "content": "Agent that retrieves business information from a vector database and processes the response"}, "typeVersion": 1}, {"id": "e2bdbd64-3c37-4867-ae2c-0f6937d82b81", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "position": [-1100, 1260], "parameters": {"height": 240, "content": "Convert email to Markdown format for better understanding of LLM models"}, "typeVersion": 1}, {"id": "8ae5d216-5897-4c33-800a-27ff939b174a", "name": "Sticky Note7", "type": "n8n-nodes-base.stickyNote", "position": [620, 1300], "parameters": {"height": 180, "content": "If the feedback is OK send email"}, "typeVersion": 1}, {"id": "4cfce63c-5931-45c5-99ca-eb85dca962b5", "name": "Approve Email", "type": "n8n-nodes-base.emailSend", "position": [380, 1340], "webhookId": "4f9f06e7-9b2b-4896-9b51-245972341d12", "parameters": {"message": "=<h3>MESSAGE</h3>\n{{ $('Email Trigger (IMAP)').item.json.textHtml }}\n\n<h3>AI RESPONSE</h3>\n{{ $json.email }}", "options": {}, "subject": "=[Approval Required] {{ $('Email Trigger (IMAP)').item.json.subject }}", "toEmail": "info@n3witalia.com", "fromEmail": "info@n3witalia.com", "operation": "sendAndWait"}, "credentials": {"smtp": {"id": "", "name": "[Your smtp]"}}, "typeVersion": 2.1}, {"id": "d6c8acd2-ebc1-4aaa-bfcc-cdb18fcc8715", "name": "OpenAI Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [-820, 1560], "parameters": {"model": {"__rl": true, "mode": "list", "value": "deepseek-chat", "cachedResultName": "deepseek-chat"}, "options": {}}, "credentials": {"openAiApi": {"id": "", "name": "[Your openAiApi]"}}, "typeVersion": 1.2}, {"id": "33bbedeb-129a-4e99-ab5a-9e0ec4456156", "name": "Set Email text", "type": "n8n-nodes-base.set", "position": [100, 1340], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "35d7c303-42f4-4dd1-b41e-6eb087c23c3d", "name": "email", "type": "string", "value": "={{ $json.output }}"}]}}, "typeVersion": 3.4}, {"id": "2293e0e6-4f2a-4622-a610-64b65f34e1e5", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "position": [320, 1300], "parameters": {"height": 180, "content": "Human in the loop"}, "typeVersion": 1}, {"id": "510196ec-adaf-4e6c-aac0-8ca8b754438a", "name": "Sticky Note11", "type": "n8n-nodes-base.stickyNote", "position": [-1100, 940], "parameters": {"color": 3, "width": 540, "height": 260, "content": "# How it works\nThis workflow automates the handling of incoming emails, summarizes their content, generates appropriate responses and validate it through send IMAP email with \"Human in the loop\" system. \n\nYou can quickly integrate Gmail and Outlook via the appropriate nodes"}, "typeVersion": 1}, {"id": "c4c9157d-4d05-47a1-a5eb-63865e838d39", "name": "Approved?", "type": "n8n-nodes-base.if", "position": [680, 1340], "parameters": {"options": {}, "conditions": {"options": {"version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict"}, "combinator": "and", "conditions": [{"id": "62e26bc5-1732-4699-a602-99490c7406fd", "operator": {"type": "boolean", "operation": "true", "singleValue": true}, "leftValue": "={{ $json.data.approved }}", "rightValue": ""}]}}, "typeVersion": 2.2}], "active": false, "pinData": {}, "settings": {"executionOrder": "v1"}, "versionId": "47e79286-00f4-48e8-a0d1-e0f56d9ba0d5", "connections": {"OpenAI": {"ai_languageModel": [[{"node": "Write email", "type": "ai_languageModel", "index": 0}]]}, "Markdown": {"main": [[{"node": "Email Summarization Chain", "type": "main", "index": 0}]]}, "Approved?": {"main": [[{"node": "Send Email", "type": "main", "index": 0}], []]}, "Write email": {"main": [[{"node": "Set Email text", "type": "main", "index": 0}]]}, "Approve Email": {"main": [[{"node": "Approved?", "type": "main", "index": 0}]]}, "Set Email text": {"main": [[{"node": "Approve Email", "type": "main", "index": 0}]]}, "OpenAI Chat Model": {"ai_languageModel": [[{"node": "Email Summarization Chain", "type": "ai_languageModel", "index": 0}]]}, "Email Trigger (IMAP)": {"main": [[{"node": "Markdown", "type": "main", "index": 0}]]}, "Email Summarization Chain": {"main": [[{"node": "Write email", "type": "main", "index": 0}]]}}}

How to Import This Workflow

  1. 1Copy the workflow JSON above using the Copy Workflow JSON button.
  2. 2Open your n8n instance and go to Workflows.
  3. 3Click Import from JSON and paste the copied workflow.

Don't have an n8n instance? Start your free trial at n8nautomation.cloud

Related Templates

Send specific PDF attachments from Gmail to Google Drive using OpenAI

Automatically extract and categorize specific PDF attachments from incoming Gmail emails and upload them to designated Google Drive folders based on their content, leveraging OpenAI's advanced text analysis capabilities. This marketing workflow begins with the Gmail trigger "On email received," which then checks if the email "Has attachments?" If attachments are present, the workflow iterates through them, identifying if each is a PDF. For each identified PDF, the "Read PDF" node extracts its textual content. This content is then evaluated by the "Is text within token limit?" node to ensure it's suitable for OpenAI processing. If within limits, the "OpenAI matches PDF textual content" node analyzes the text against predefined criteria. Based on whether the PDF is "matched" by OpenAI, the "Upload file to folder" node in Google Drive stores the relevant PDFs, while unmatched or non-PDF attachments are handled accordingly. This workflow is ideal for marketing teams needing to automatically sort client contracts, campaign reports, or specific vendor invoices received via email, ensuring critical documents are filed correctly without manual intervention. It significantly reduces the time spent on document organization and improves data accessibility, allowing teams to focus on strategic marketing initiatives rather than administrative tasks.

18 nodes

Auto categorize wordpress template

Automatically categorize your WordPress posts with the power of AI. This workflow connects your WordPress site with OpenAI's advanced language models to intelligently analyze your content and assign appropriate categories. When you manually trigger this workflow, it first retrieves all your WordPress posts using the "Get All Wordpress Posts" node. This data then flows into an AI Agent, which leverages the "OpenAI Chat Model" to understand the context and content of each post. Based on this analysis, the AI Agent then interacts with your WordPress site to update the categories of your posts, streamlining your content management. This is incredibly useful for bloggers, content marketers, and website administrators who manage large volumes of content and want to ensure their posts are consistently and accurately categorized without manual effort. It saves significant time and reduces the potential for human error in content organization, making your website more navigable and improving SEO.

9 nodes

Effortless Email Management with AI

Automate your email management by intelligently processing incoming messages, summarizing their content, and drafting personalized replies with AI. This powerful workflow connects your Gmail inbox via an IMAP trigger to a Text Classifier that categorizes emails, then uses OpenAI for summarization and drafting responses, and Qdrant for vector storage of relevant documents from Google Drive. It’s ideal for marketing teams, customer support, or busy professionals who need to efficiently handle high volumes of correspondence, saving significant time on reading, understanding, and responding to emails by leveraging AI to streamline communication and ensure timely, relevant replies. The system also allows for reviewing AI-generated drafts before sending, ensuring quality control while drastically reducing manual effort.

31 nodes

Ready to automate with n8n?

Get affordable managed n8n hosting with 24/7 support.