n8n

How to Automate Gmail AI Assistant for HTML Replies and Labeling?

Manage your Gmail inbox with an AI email assistant that writes, sends, files, and replies in clean HTML. Great for support or shared inbox teams that want faster answers without hopping between tools. It keeps messages organized and drafts ready when human review is needed.

Another workflow triggers it and passes a plain language request into an Email Agent powered by the OpenAI Chat Model. The agent can fetch messages by sender and limit, send new emails, reply by message ID, create HTML drafts, read labels, add labels, and mark threads as unread. All Gmail actions run through secure Gmail tools while the agent fills in subjects, bodies, recipients, and label IDs. A Success node returns the result, and a Try Again path returns a friendly error if inputs are missing.

Set up Gmail OAuth and an OpenAI key, then edit the agent system message to match your tone and signature. Expect shorter response times and less manual sorting, especially for triage, quick follow ups, and labeling rules. Teams can kick it off from any upstream workflow to standardize inbox work across brands or departments.

What are the key features?

  • Starts when another workflow calls it, so teams can reuse the same inbox logic anywhere.
  • Email Agent uses the OpenAI Chat Model to decide which Gmail action to run.
  • Send Email creates a new message with AI drafted subject, body, and recipient.
  • Email Reply answers an existing thread by message ID using clean HTML content.
  • Create Draft builds an HTML draft so a human can review before sending.
  • Get Emails filters by sender and limit to focus on the right messages.
  • Get Labels lists all labels, and Label Emails applies specific label IDs.
  • Mark Unread resets threads to unread for follow up tracking.
  • Success and Try Again return clear outputs for downstream steps.

What are the benefits?

  • Reduce manual triage from 2 hours to 15 minutes per day
  • Automate up to 70% of routine replies and follow ups
  • Shorten first response time from hours to minutes
  • Improve label accuracy by 80% with clear label IDs
  • Handle 5 times more messages with the same team
  • Connect Gmail and OpenAI in one repeatable flow

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 the n8n credentials manager, connect Gmail. Double click any Gmail node, select the 'Credential to connect with' dropdown, click 'Create new credential', then follow the on screen steps. Use the Google account that will send and manage emails, and grant permission to read, send, and manage labels.
  4. Set up OpenAI. Double click the OpenAI Chat Model node, choose 'Credential to connect with' > 'Create new credential', then paste an API key from the OpenAI account API page. Save the credential.
  5. In the OpenAI Chat Model node, confirm the model is set to gpt-4o and the correct OpenAI credential is selected.
  6. Open the Email Agent node. Review the system message to set tone and signature for emails. Keep the instruction to use professional HTML. The input text should read the query from {{$json.query}}.
  7. Optional validation for labels: run the Get Labels node once to list available labels in Gmail, then use those label IDs in your requests when labeling emails.
  8. Create a small caller workflow: add a Manual Trigger, then an Execute Workflow node. Point it to this inbox workflow and send an input with a 'query' field, for example: "Find the last 5 emails from alice@example.com and label them Prospects."
  9. Test end to end. Run the caller workflow, check the Success output in n8n, and review Gmail for new drafts, replies, labels, or unread status changes.
  10. Troubleshoot common issues: if you see the Try Again message, include missing details like message ID or recipient email. Confirm the Gmail credential has the right scopes, and make sure the caller workflow passes a 'query' field to the agent.

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.