AI Powered Email Assistant: Automate Your Inbox with n8n & OpenAI

Learn AI Powered Email Assistant: Automate Your Inbox with n8n & OpenAI in this comprehensive n8n tutorial. Step-by-step guide with video, code examples, and expert tips from the n8n Zero to Hero course.

Table of Contents

Overview

This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 6. AI-Powered Workflows.

Watch the video above for the full tutorial, or read the written guide below.

What is an AI-powered email assistant in n8n?

The AI-powered email assistant workflow in n8n reads your Gmail inbox on a schedule, uses OpenAI's gpt-4o-mini to summarize each unread email and decide whether a reply is needed, then drafts a polite HTML reply when one is required. It saves that reply as a Gmail draft, sends a Telegram notification with Approve and Decline buttons, and dispatches the email automatically only after you tap Approve, with no code written.

How to build an AI-powered email assistant in n8n

The Schedule Trigger node fires at 8 AM daily (hour set to 8, minute set to 0). Add a Manual Trigger alongside it for test runs. A Gmail "Get Many Messages" node fetches unread inbox messages with the Simplify toggle disabled, because leaving Simplify on returns only a short snippet rather than the full email body, thread ID, and sender address the downstream nodes need. Set the limit to 1 during development so you can step through emails one at a time, and filter by label "inbox" and read status "unread."

The OpenAI node targets gpt-4o-mini and takes two messages. The System message tells the model it is a helpful email assistant and instructs it to always draft replies in HTML format. The User message provides the email body and asks for a JSON response with three fields: summary (one sentence), reply_needed (the string "yes" or "no"), and suggested_reply (an HTML draft). Enabling "Output Content as JSON" in the OpenAI node strips surrounding prose automatically. An IF node then checks whether reply_needed equals "yes" (with the ignore-case option enabled to handle any capitalization the model returns) and routes only matching emails forward.

The Gmail "Create Draft" node sets the email type to HTML, populates the body from suggested_reply, prefixes the subject with "Re:", and passes the original message's Thread ID via the "Add Option" menu to attach the draft to the correct conversation thread. The To address comes from the from field of the fetched email. The Telegram node then sends the summary and draft to your personal bot chat with "Send and Wait for Response" enabled, response type set to Approval, and the "Approve and Disapprove" option selected, which renders two buttons in the app and pauses the workflow. When you tap Approve, the webhook returns approved: true. A Gmail "Get Draft" node retrieves the saved draft by its ID, and an HTTP POST node calls https://gmail.googleapis.com/gmail/v1/users/me/drafts/send with the draft ID in the body and your Gmail OAuth2 credential for authentication, dispatching the reply and clearing the draft from your inbox.

Key Takeaways

  • The Schedule Trigger node runs at 8 AM daily; swap it for a Gmail "On Email Arrival" trigger once the workflow is tested to process emails in real time rather than in a morning batch.
  • The Gmail "Get Many Messages" node requires Simplify to be disabled; the default Simplify-on mode returns only a snippet and omits the thread ID and full body the workflow depends on.
  • The OpenAI System prompt enforces HTML reply format, and the User prompt specifies the exact three-field JSON schema (summary, reply_needed, suggested_reply) so n8n parses the response without extra cleanup.
  • Thread ID from the fetched email must be passed to the Gmail "Create Draft" node via "Add Option" to tie the AI reply to the original conversation thread.
  • n8n has no native "Send Draft" operation on the Gmail node, so an HTTP POST to https://gmail.googleapis.com/gmail/v1/users/me/drafts/send with the draft ID and Gmail OAuth2 credential is the correct workaround.

Next Steps

Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.

Frequently Asked Questions

The Gmail node's Simplify toggle is on by default, which trims the response to a snippet. Disabling Simplify returns the full email body, thread ID, sender address, and all headers that the OpenAI summarization node and the Gmail 'Create Draft' node all require to function correctly.

The gpt-4o-mini model returns a three-field JSON object: `summary` (a one-sentence description of the email), `reply_needed` (the string "yes" or "no"), and `suggested_reply` (a full HTML-formatted draft reply). Enabling 'Output Content as JSON' in the OpenAI node removes any surrounding prose so n8n can parse the fields directly.

The Telegram node sends the email summary and suggested reply to your personal bot chat, then halts workflow execution and listens on a webhook. Choosing the Approval response type with 'Approve and Disapprove' renders two in-app buttons. Tapping Approve sends a webhook payload where `approved` equals true, which resumes the workflow and triggers the draft-send steps.

The n8n Gmail node has no native 'Send Draft' operation. The correct workaround is an HTTP POST node that calls `https://gmail.googleapis.com/gmail/v1/users/me/drafts/send` with the draft ID in the request body and the Gmail OAuth2 credential set under predefined credentials, which dispatches the reply and removes the draft from the inbox.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources