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/sendwith the draft ID and Gmail OAuth2 credential is the correct workaround.
Related Lessons
- Lesson 36: AI Automation with n8n: Supercharge Your Workflows with OpenAI
- Lesson 38: AI Blog Writer
- Lesson 39: AI Resume Screening
Next Steps
Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.