n8n

How to Automate Gmail AI Reply Drafts?

Turn labeled emails into ready to send drafts in Gmail. The flow scans your inbox on a schedule, reads the newest message in each labeled thread, and writes a helpful reply with an AI assistant. Ideal for support and sales inboxes that need fast, consistent first responses.

A minute based trigger starts the run. Gmail nodes find threads with a chosen label and fetch only the last message, so AI context stays relevant. The message goes to an OpenAI Assistant, which returns a Markdown reply. The flow converts Markdown to HTML, builds an RFC 822 email, encodes it to base64, and creates a draft in the same thread. The label is then removed to prevent a second pass.

Set up Gmail OAuth and an OpenAI API key, then pick the label to watch. Expect faster replies and less typing while agents keep full control by reviewing drafts before sending. Use it for support queues, lead intake, and shared inboxes that need a steady tone and quick follow up.

What are the key features?

  • Schedule trigger checks for new labeled threads every minute
  • Gmail search pulls threads with a specific label set by your team
  • Batch loop processes threads one by one for stable performance
  • Gets only the last message in each thread to keep replies on topic
  • Sends message content to an OpenAI Assistant to generate a draft reply
  • Converts Markdown from the AI into clean HTML for email
  • Builds an RFC 822 message and encodes it to base64 as required by Gmail
  • Creates a Gmail draft in the original thread using the Gmail API
  • Removes the trigger label after drafting to avoid repeat processing

What are the benefits?

  • Reduce manual drafting from about 3 minutes per email to under 30 seconds
  • Automate up to 70 percent of first reply writing while keeping human review
  • Keep formatting clean by converting Markdown to proper HTML
  • Handle hundreds of labeled threads per hour with batch looping
  • Connect Gmail and OpenAI in one workflow without switching tools

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Gmail and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. In n8n Cloud, double click any Gmail node, open the Credential to connect with dropdown, click Create new credential, then follow the on screen steps to connect your Google account with OAuth2.
  4. Double click the Ask OpenAI Assistant node, click Create new credential, then paste your OpenAI API key from the OpenAI account API page. Save the credential.
  5. In the Schedule Trigger node, set the interval to 1 minute or choose a timing that fits your inbox volume.
  6. Open the Gmail node that gets threads and set the label you want to watch. Use a label that your team applies to conversations that need an AI draft.
  7. Open the Ask OpenAI Assistant node and select your Assistant or provide the Assistant ID. Adjust instructions and variables so the reply tone matches your brand.
  8. In the Convert response to HTML node, keep Markdown to HTML enabled so drafts render well in email clients.
  9. Open the Build email raw node and confirm To and Subject map from the Gmail message fields. Make sure threadId is mapped in the downstream Set node.
  10. Open the HTTP Request node that creates the draft and verify it uses the Gmail OAuth2 credential. Confirm the JSON body includes the encoded raw message and threadId.
  11. Run a test: in Gmail, apply the chosen label to a thread with a new message. Check n8n Executions to see the run. Confirm a draft appears in the same thread and the label is removed.
  12. If no draft appears, check n8n error logs, confirm Gmail credential consent includes mail compose scope, verify the base64 encoding step, and make sure the label name and threadId mapping are correct.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.