Advanced Extended

Build an automated mail responder with n8n

By Angus Published 14 May 2026 14 min read

Manually replying to routine enquiries takes time away from higher-value work. By connecting an IMAP inbox to an AI pipeline in n8n, you can automatically read incoming emails, classify them, generate a professional reply and send it, all without human intervention.

This guide walks you through building a complete automated mail responder workflow in n8n. The finished workflow monitors an inbox, summarises each message, classifies it, drafts a reply using OpenAI, reviews that reply with a second model, and sends the response via SMTP. A Qdrant vector database backs the response generation with relevant documents pulled from Google Drive.

Before you begin

  • You need a running n8n instance. See our guide on installing CloudPanel on a VPS if you need a server to host n8n on.
  • You need an email account with IMAP access enabled and SMTP credentials for sending.
  • You need an OpenAI API key and a DeepSeek API key.
  • You need a Qdrant instance (cloud or self-hosted) with an API key and a collection name ready.
  • You need a Google Drive folder containing the documents you want the AI to reference when answering enquiries.
  • We recommend installing the n8n CLI to manage your workflow from the command line. Install it globally with npm install -g @n8n/cli or run it directly with npx @n8n/cli workflow list.

How the automated mail responder works

Before building each node, it helps to understand the full data path. Each incoming email passes through a chain of processing steps, and knowing the purpose of each step makes it easier to debug problems later.

The workflow follows this sequence:

  • Email Trigger (IMAP) – polls your inbox and fires the workflow when a new message arrives.
  • Markdown node – strips HTML from the email body and converts it to plain text so the AI models receive clean input.
  • Email Summarisation Chain – uses DeepSeek R1 to produce a short summary of the message.
  • Email Classifier – categorises the email (for example, Company info request or Other) using GPT-4o-mini.
  • Qdrant Vector Store – retrieves relevant document chunks from your vector database when the email is classified as a company info request.
  • Write Email node – drafts a reply using OpenAI, drawing on the retrieved context.
  • Review Email node – passes the draft to DeepSeek for a second pass, formatting the output as HTML.
  • Send Email node – delivers the finished response to the original sender via SMTP.

A separate document vectorisation branch handles loading your Google Drive files into Qdrant. You run this branch once to populate the database, then refresh it whenever your documents change.

Configure the email trigger

The Email Trigger node is the entry point for the workflow. It connects to your inbox over IMAP and passes each new message downstream as a data object.

  1. Add an Email Trigger (IMAP) node.
    In the n8n canvas, click the + button and search for Email Trigger (IMAP). Add it as the first node.
  2. Create IMAP credentials.
    Click Credential for IMAP account, then Create new. Enter your mail server hostname, port (typically 993 for SSL), your email address and password.
  3. Set the mailbox and polling interval.
    Set Mailbox Name to INBOX and choose a polling frequency. One minute is a reasonable starting point for most business inboxes.
  4. Enable the download of email body.
    Toggle Download Attachments off unless you need them. Toggle Format to include the HTML body so the Markdown node can process it in the next step.

With the trigger configured, the workflow now has a live data source. The next step cleans the email body before it reaches the AI models.

Pre-process and summarise the email

HTML email bodies contain tags, inline styles and encoded characters that confuse language models. Converting to plain text first produces more accurate summaries and classifications.

  1. Add a Markdown node.
    Connect it to the Email Trigger output. In the node settings, map the HTML input field to {{ $json.html }} (the HTML body field from the IMAP node). The output will be clean plain text.
  2. Add a Summarisation Chain node.
    Search for Summarisation Chain and connect it after the Markdown node. This node orchestrates the summarisation prompt.
  3. Attach a DeepSeek R1 language model.
    Add a DeepSeek Chat Model sub-node and connect it to the Summarisation Chain as the language model. Configure it with your DeepSeek API key and select the deepseek-reasoner model.
  4. Set the summarisation prompt.
    In the Summarisation Chain node, set the prompt to instruct the model to produce a summary of no more than 100 words. Adjust the language instruction to match your business needs.

The summarisation output feeds into the classifier, giving it a condensed version of the email rather than the full body.

Classify incoming emails

Classification routes each email to the correct response path. An email asking about your company gets a context-aware reply drawn from your document store; everything else follows a generic path.

  1. Add a Text Classifier node.
    Connect it after the Summarisation Chain. This node uses a language model to assign a category label to each email.
  2. Attach a GPT-4o-mini model.
    Add an OpenAI Chat Model sub-node, configure it with your OpenAI API key and select gpt-4o-mini as the model. Connect it to the Text Classifier as the language model.
  3. Define your categories.
    In the Text Classifier node, add two categories: Company info request and Other. Add a description for each so the model understands the distinction. For example: Company info request – the sender is asking about the business, its services, pricing or contact details.
  4. Connect the output branches.
    The Text Classifier produces one output per category. Connect the Company info request output to the Qdrant retrieval branch. Connect the Other output directly to the Write Email node, bypassing vector retrieval.

With classification in place, the workflow can now apply different logic depending on what the sender needs.

Connect the Qdrant vector database

The vector database stores embeddings of your company documents. When an email is classified as a company info request, the workflow queries Qdrant to retrieve the most relevant document chunks and passes them to the response-generation model as context.

  1. Add a Qdrant Vector Store node (retrieval mode).
    Connect it to the Company info request output of the Text Classifier. Set the Operation Mode to Retrieve Documents (As Vector Store for Chain).
  2. Configure Qdrant credentials.
    Click Credential for Qdrant API and enter your Qdrant instance URL and API key. Set the Collection Name to the collection you created for your company documents.
  3. Add an Embeddings OpenAI node.
    Connect it to the Qdrant Vector Store node as the embedding model. Configure it with your OpenAI API key and select text-embedding-3-small or text-embedding-ada-002. This node converts the incoming email text into a vector so Qdrant can find similar document chunks.
  4. Connect the retrieval output to the Write Email node.
    The Qdrant node outputs retrieved document chunks. Pass these into the context field of the Write Email node in the next step.

The retrieved context gives the response model accurate, up-to-date information about your business rather than relying on the model’s training data alone.

Generate and review the email reply

Two AI nodes handle response generation. The first drafts the reply; the second reviews it for tone and formats it as HTML ready for sending.

  1. Add a Basic LLM Chain node (Write Email).
    Connect it after the Qdrant retrieval output (and separately after the Other classifier branch). Set the system prompt to instruct the model to write a professional reply of no more than 100 words, using the retrieved context where available.
  2. Attach an OpenAI Chat Model to the Write Email node.
    Add an OpenAI Chat Model sub-node, select gpt-4o or gpt-4o-mini and connect it as the language model.
  3. Add a second Basic LLM Chain node (Review Email).
    Connect it after the Write Email node. Set the system prompt to instruct the model to review the draft for professionalism and reformat it as HTML, using tags such as <br>, <b>, <i> and <p> where appropriate.
  4. Attach a DeepSeek Chat Model to the Review Email node.
    Add a DeepSeek Chat Model sub-node, select deepseek-chat and connect it as the language model for the review step.

Using two models in sequence means the first model focuses on content accuracy while the second focuses on presentation, producing a more consistent output than a single prompt would.

Send the response

The final node in the main branch delivers the formatted reply to the original sender using SMTP.

  1. Add a Send Email node.
    Connect it after the Review Email node. Search for Send Email in the node panel.
  2. Configure SMTP credentials.
    Click Credential for SMTP account and enter your outgoing mail server hostname, port (587 for STARTTLS or 465 for SSL), username and password.
  3. Map the recipient and subject fields.
    Set To Email to {{ $('Email Trigger (IMAP)').item.json.from.value[0].address }} to reply to the original sender. Set Subject to Re: {{ $('Email Trigger (IMAP)').item.json.subject }}.
  4. Set the email body.
    Set Email Type to HTML and map the HTML body field to the output of the Review Email node: {{ $json.text }}.

The main workflow branch is now complete. Incoming emails are read, summarised, classified, answered and sent without manual intervention.

Populate the Qdrant vector database from Google Drive

The retrieval step only works if your Qdrant collection contains document embeddings. This separate branch loads your company documents from Google Drive, splits them into chunks and stores them as vectors. Run it once to populate the collection, then re-run it whenever your documents change.

  1. Add a manual trigger node.
    Use a When clicking ‘Test workflow’ node as the trigger for this branch so you can run it on demand without affecting the main email flow.
  2. Add a Google Drive node (Get folder).
    Configure it with your Google OAuth2 credentials. Set the operation to Get Many and point it at the folder containing your company documents.
  3. Add a Google Drive node (Download Files).
    Connect it after the Get folder node. Set the operation to Download and map the file ID from the previous node’s output.
  4. Add a Default Data Loader node.
    Connect it after the Download Files node. This node prepares the downloaded file content for the text splitter.
  5. Add a Token Splitter node.
    Connect it after the Default Data Loader. Set the chunk size to 500 tokens and the chunk overlap to 50 tokens. Smaller chunks improve retrieval precision; overlap prevents context being cut mid-sentence.
  6. Add a Qdrant Vector Store node (insert mode).
    Connect it after the Token Splitter. Set the Operation Mode to Insert Documents. Use the same collection name and Qdrant credentials as the retrieval node.
  7. Add a second Embeddings OpenAI node.
    Connect it to the Qdrant insert node as the embedding model. Use the same model as the retrieval branch (text-embedding-3-small or text-embedding-ada-002) so that query and document vectors are in the same space.

Once this branch has run successfully, your Qdrant collection is ready to serve relevant context to the response generation model.

Test and activate the workflow

Testing before activation catches credential errors and misconfigured expressions before they affect real senders.

  1. Run the vectorisation branch.
    Click Test workflow on the manual trigger to load your documents into Qdrant. Check the Qdrant dashboard to confirm the collection contains records.
  2. Send a test email to your monitored inbox.
    Send a message asking a question about your company. Wait for the polling interval to pass, or click Execute Node on the IMAP trigger to fetch immediately.
  3. Inspect each node’s output.
    Click through the execution log in n8n. Confirm the Markdown node produces clean text, the classifier assigns the correct category, the Qdrant node returns relevant chunks and the Review Email node outputs valid HTML.
  4. Check the sent reply.
    Open the inbox of the address you sent the test from and confirm the reply arrived, is correctly addressed and reads as expected.
  5. Activate the workflow.
    Once all steps pass, toggle the workflow to Active using the switch in the top-right corner of the canvas. The IMAP trigger will now poll continuously.

The workflow is now live. Every new email that arrives in the monitored inbox will be processed and replied to automatically.

Troubleshooting

The IMAP trigger does not fire

If the trigger never activates, the most common cause is a credential or connection problem between n8n and your mail server.

  • Confirm IMAP is enabled on your email account. Many providers disable it by default.
  • Check that port 993 is not blocked by a firewall on your VPS. See our guide on opening ports in UFW.
  • Verify the credentials in n8n by clicking Test credential in the IMAP credential panel.
  • If you use Gmail, enable Less secure app access or generate an app-specific password.

The Qdrant node returns no results

Empty retrieval results usually mean the collection was not populated, or the embedding model used during insertion does not match the one used during retrieval.

  • Re-run the vectorisation branch and check the Qdrant dashboard for a non-zero point count.
  • Confirm Embeddings OpenAI nodes use the same model name.
  • Check that the collection name in the retrieval node matches the one used during insertion exactly, including case.
  • Increase the Top K value in the Qdrant retrieval node to return more candidate chunks.

The Send Email node fails

SMTP failures are almost always caused by incorrect credentials or a blocked outgoing port.

  • Test the SMTP credentials independently using a tool such as curl or a desktop mail client before entering them in n8n.
  • Confirm port 587 or 465 is open on your server. See our guide on opening ports in firewalld.
  • Check that the From Email address matches the authenticated SMTP account. Many providers reject mismatched sender addresses.

The AI model returns an error or empty output

API errors from OpenAI or DeepSeek are usually caused by invalid keys, rate limits or malformed prompts.

  • Check the execution log in n8n for the exact error message returned by the API.
  • Confirm your API keys are active and have sufficient quota in the respective provider dashboards.
  • If the Markdown node output is empty, the IMAP node may not be returning an HTML body. Switch the input expression to {{ $json.text }} to use the plain-text body instead.

Further reading on n8n workflow automation

The workflow you built here covers one common automation pattern: inbound email triage and response. n8n supports hundreds of integrations, so the same principles apply to other communication channels and data sources.

If you want to extend this workflow, consider adding a Slack or Teams notification node on the Other branch so a human agent is alerted when an email falls outside the automated categories. You could also add a Google Sheets node to log every processed email, giving you a record of what was sent and when.

For the infrastructure side, running n8n on a VPS gives you full control over polling intervals, memory allocation and outbound IP addresses. A dedicated outbound IP is particularly useful if your SMTP provider enforces IP-based sending limits. Our guide on securing your VPS covers the baseline hardening steps you should apply before exposing any service to the internet.

Managing workflows from the command line is covered in the n8n CLI documentation. You can list, export and import workflows without opening the browser interface, which is useful for version-controlling your automations in Git. Our guide on adding an SSH key to GitHub walks through connecting your server to a repository.

For a broader look at what you can self-host on a VPS alongside n8n, the Node.js hosting page covers compatible environments. The n8n project also maintains a full list of built-in app nodes where you can browse available integrations and their configuration options.

Wrapping up

You have built a complete automated mail responder in n8n. The workflow monitors an inbox via IMAP, converts and summarises each message, classifies it with GPT-4o-mini, retrieves relevant context from a Qdrant vector database, drafts a reply with OpenAI, reviews it with DeepSeek and sends the finished response via SMTP.

Review the execution logs over the first few days to confirm classifications are accurate and replies read naturally. Adjust the system prompts in the Write Email and Review Email nodes to match your brand voice. For related tasks, see our guides on installing Node.js on Linux, installing Docker Compose (useful for self-hosting Qdrant) and managing firewall ports on your VPS.

Running n8n on a VPS from Unlimited Web Hosting gives you the resources and network access this kind of always-on automation workflow needs.

Ready to get started?

Launch your website with our reliable cPanel hosting with unlimited bandwidth and expert support.

Get cPanel Hosting

Need a domain?

Find and register the perfect domain name for your website.

Search Domains