Skip to content

Sort your Gmail with AI labels, set up from your assistant

Your assistant builds an automation that checks for new mail on a schedule, labels each message (invoice, customer, newsletter, needs reply), and tells you in Slack or by email when something is urgent.

Your assistantClickRuntime connected
Create a ClickRuntime automation: every 15 minutes, label my new Gmail messages as Invoice, Customer, Newsletter or Needs reply.
I'll check for new mail every 15 minutes, label each message with AI, and remember which messages I've already handled.
Gmail AI labelsLive
When
Every 15 minutes
Uses
Gmail
RunsClickRuntime dashboard
  • 10:45✓ Gmail AI labels · SucceededLast run10:45 · 6 labelled

Can ChatGPT or Claude sort my Gmail automatically?

An assistant with a Gmail connector can sort mail while you're chatting. It doesn't keep working in the background or remember which messages it already handled. With ClickRuntime, the assistant sets up an automation that checks Gmail every 15 minutes (or as often as every 5), labels new messages with the built-in AI, and remembers where it left off.

Why the assistant can’t do this on its own

  • No background work. Sorting has to happen when mail arrives, not when you next open a chat.
  • No memory of what was handled. The automation keeps the last message it labelled in its state, so nothing is labelled twice or skipped.
  • Gmail filters only match fixed words. AI labels read the message and decide, which handles the mail filters miss.

Set it up from your AI assistant

The same steps work in ChatGPT, Claude, Cursor and any assistant that supports MCP connectors.

  1. Step 1Connect ClickRuntime to your assistantAdd ClickRuntime as a connector (MCP server) in ChatGPT, Claude, Cursor or another MCP client, using https://clickruntime.com/api/mcp. You sign in with Google or email; there is no API key to copy. This is done once per assistant.
  2. Step 2Paste the promptStart a new chat and paste: “Create a ClickRuntime automation: every 15 minutes, look at new messages in my Gmail inbox and add one label: Invoice, Customer, Newsletter or Needs reply. Email me straight away when a customer message sounds urgent.” Change the details (times, channels, addresses) to yours.
  3. Step 3Read the draftThe assistant restates what will happen, asks for anything missing, such as your timezone or which channel to post to, and saves a draft automation. A draft never runs on its own, so nothing happens until you agree.
  4. Step 4Connect accounts and save keysThe assistant asks you to connect your Google account in the ClickRuntime dashboard with Gmail access (Google's own consent screen). It creates the four labels in Gmail with a one-time setup script if they don't exist.
  5. Step 5Test itThe assistant runs it once against the last day of mail and shows which label each message got, before turning on the schedule. You can ask it to change the rules if a label looks wrong.
  6. Step 6Turn it onThe assistant tells you what will run, when, and which services it will contact, then asks your permission to turn it on. From then on it runs on ClickRuntime's servers, and you can close the chat.
  7. Step 7Check it in the ClickRuntime dashboardEach run shows how many new messages it found and labelled. Runs that find nothing new and finish quickly aren't counted toward your monthly runs. State shows the time of the last message handled.
Prompt to copy.txt

“Create a ClickRuntime automation: every 15 minutes, look at new messages in my Gmail inbox and add one label: Invoice, Customer, Newsletter or Needs reply. Email me straight away when a customer message sounds urgent.”

Connector setup for each assistant: ChatGPT, Claude, Claude Code, Cursor, and other assistants.

What the assistant writes

A typical script for this job. Yours matches your pages, accounts and wording, and you can read every version in the ClickRuntime dashboard.

gmail_ai_labels.pyexample
1from google.oauth2.credentials import Credentials
2from googleapiclient.discovery import build
3from clickruntime import on_trigger, report_fetched, credentials, state, ai, notify
4 
5LABEL_IDS = {"Invoice": "Label_1", "Customer": "Label_2", "Newsletter": "Label_3", "Needs reply": "Label_4"}
6SCHEMA = {"type": "object", "properties": {
7"label": {"type": "string", "enum": list(LABEL_IDS)}, "urgent": {"type": "boolean"}},
8"required": ["label", "urgent"]}
9 
10@on_trigger
11def run(event):
12gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
13since = state.get("since") or 0
14q = "in:inbox" + (f" after:{since}" if since else " newer_than:1d")
15ids = [m["id"] for m in gmail.users().messages().list(userId="me", q=q, maxResults=50).execute().get("messages", [])]
16done = set(state.get("done") or [])
17new = [i for i in ids if i not in done]
18report_fetched(len(new))
19if not new:
20return {"summary": "Nothing new"}
21 
22newest = since
23for mid in new:
24m = gmail.users().messages().get(userId="me", id=mid, format="metadata",
25metadataHeaders=["From", "Subject"]).execute()
26h = {x["name"]: x["value"] for x in m["payload"]["headers"]}
27text = f"From: {h.get('From')}\nSubject: {h.get('Subject')}\n{m.get('snippet', '')}"
28try:
29d = ai.generate(text, system="Label this email.", json_schema=SCHEMA, max_output_tokens=40).json
30except ai.AIError:
31d = {"label": "Needs reply", "urgent": False}
32gmail.users().messages().modify(userId="me", id=mid, body={"addLabelIds": [LABEL_IDS[d["label"]]]}).execute()
33if d["urgent"] and d["label"] == "Customer":
34notify.email_me("Urgent: " + (h.get("Subject") or "")[:150], text)
35newest = max(newest, int(m["internalDate"]) // 1000)
36 
37state.set("since", newest)
38state.set("done", (list(done) + new)[-500:])
39return {"labelled": len(new)}
  • Only the sender, subject and Gmail's short snippet are sent to the AI, not the full message or attachments.
  • Label ids come from the one-time setup script that created the labels; the assistant writes them into the script.
  • The automation remembers the newest message time and the last 500 message ids, so each message is labelled once.

A schedule, not a trigger link

Use a schedule. Every 15 minutes suits most inboxes; 5 minutes is the shortest interval.

Checks that find no new mail return straight away and, when they finish quickly, aren't counted toward your monthly runs.

Limits

  • The shortest interval is every 5 minutes, so labels appear within minutes, not instantly.
  • Up to 50 calls to the built-in AI per run; the script handles at most 50 messages per run and picks up the rest next time.
  • Gmail access uses your own Google OAuth app added in the ClickRuntime dashboard.

Troubleshooting

Runs fail with 403 insufficient permissions.

The Google connection was made without Gmail access. Reconnect it in the ClickRuntime dashboard and allow Gmail.

Labels are wrong for some senders.

Tell your assistant, for example “mail from billing@ is always Invoice”. It adds a rule before the AI step, which also saves AI tokens.

It stopped labelling.

Check the run log in the ClickRuntime dashboard. A failed run sends you an email; ask your assistant to read the error and fix it.

What you can add next

The first version is rarely the last. Because the automation is a Python script with memory, AI and any API available, you grow it by asking your assistant for the change. Each change is a new version, and a failed deploy never replaces the working one.

  • Built-in AI

    Draft replies to customer messages and leave them in Gmail drafts

    “Change my Gmail AI labels automation so that for each Customer message it saves a short draft reply in Gmail for me to edit and send.”
  • Any app or API

    Post urgent customer messages to #support in Slack

    “Change my Gmail AI labels automation so urgent customer messages are posted to #support in Slack instead of emailed to me.”
  • Any app or API

    Log every invoice email to a Google Sheet

    “Add to my Gmail AI labels automation: for each Invoice message, add a row to my Invoices sheet with sender, subject and date.”
  • Built-in AI

    Pull the amount and due date out of invoice emails

    “Change my Gmail AI labels automation so that for Invoice messages it also reads the amount and due date from the text and adds them to the Invoices sheet.”
  • Schedules

    A 17:00 email listing messages still labelled Needs reply

    “Add to my Gmail AI labels automation: every weekday at 17:00, email me the messages labelled Needs reply that I haven't answered.”
  • Memory between runs

    Learn senders: once a sender is labelled three times, skip AI for them

    “Change my Gmail AI labels automation so it remembers the label for each sender, and after three of the same, uses it without asking the AI.”
  • Multi-step logic

    Archive newsletters after labelling them

    “Change my Gmail AI labels automation so Newsletter messages are labelled and archived out of the inbox.”

Can ChatGPT automatically sort my Gmail?

With ClickRuntime connected, ChatGPT can set up an automation that labels new Gmail messages on a schedule, after the chat is closed. ChatGPT alone only acts while you chat.

Does the AI read my whole email?

The example sends the sender, subject and Gmail's snippet only. You can choose what is sent; attachments are never sent.

How quickly are messages labelled?

Within the schedule's interval: every 15 minutes in the example, every 5 at the shortest.

Does it work with Outlook?

Yes, through Microsoft Graph with a Microsoft OAuth app added in the ClickRuntime dashboard. Ask your assistant for Outlook instead of Gmail.

Do I need an OpenAI key?

No. The built-in AI needs no key and is included, including on the free plan.

Other use cases

Set up your first automation in ChatGPT or Claude

Free plan. No credit card.

Server URLhttps://clickruntime.com/api/mcp