n8n

How to Organize Gmail with AI Labeling and Auto Filing?

Keep your Gmail tidy without manual sorting. The system reads each new email and files it into the right label or creates a clear new one. Great for teams that want a clean inbox and faster follow up.

It starts when Gmail checks for new messages every five minutes. An AI agent reviews the subject, sender, and content, then uses Gmail tools to read labels, fetch the message, add labels, or create a label when none fit. Low value mail can have the Inbox label removed, while normal and important mail stays visible. New labels follow your naming style and are placed as sublabels under an AI parent when needed. A short memory window keeps context per message so the agent makes consistent choices. The model can handle long emails with a large token limit, and a brief wait helps space out calls.

Connect a Gmail account and add your OpenAI key to run it. Set the poll time and review the rules in the system message. Expect strong time savings and a steady folder structure across the team. This is useful for promotions, vendor mail, project updates, and resumes, and can be tuned with a few simple edits.

What are the key features?

  • Gmail trigger checks for new emails every five minutes and starts the run.
  • AI agent uses an OpenAI chat model with a large token limit to decide labels.
  • Reads all Gmail labels so it can match the best option before creating new ones.
  • Fetches the full message to analyze subject, sender, recipients, and content.
  • Creates a new label only when no good match exists and places it as a sublabel.
  • Adds the chosen label to the email and can remove the Inbox label for low value mail.
  • Short memory per message keeps decisions consistent across tool calls.
  • A small wait step spaces out requests to reduce API issues.

What are the benefits?

  • Reduce manual sorting from 60 minutes to 5 minutes per day
  • Automate up to 90 percent of email labeling
  • Improve inbox accuracy by 80 percent with consistent rules
  • Handle 5 times more email volume without extra staff
  • Connect Gmail and OpenAI with no custom code

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. Open the Gmail Trigger node, click Credential to connect with, choose Create new credential, and follow the on screen steps to connect your Gmail account with OAuth. Save the credential for reuse on all Gmail nodes.
  4. Open the OpenAI Chat Model node, click Credential to connect with, choose Create new credential, and paste your OpenAI API key from your OpenAI account API page. Save the credential.
  5. In the Gmail Trigger node, set the poll time to five minutes or your preferred interval. Enable New Email as the event if available.
  6. Open the Gmail tool nodes and make sure they use the same Gmail credential. These include read labels, get message, create label, and add label to message.
  7. Open the agent node and review the system message rules for label naming, inbox removal for ads, and sublabel placement. Adjust text to match your label style.
  8. Turn on the workflow and send a test email to your Gmail. In n8n, check the execution to verify the agent reads labels, fetches the message, and applies or creates labels.
  9. In Gmail, confirm that the email now has the correct label. Check that new labels follow your naming style and appear as sublabels under the AI parent when needed.
  10. If labels are not created, confirm the Gmail permission includes modify scope, increase the wait step slightly, and check the execution log for any tool errors.

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.