Skip to content

Daily

Clear out old promotional emails every night

Old promotions that are truly junk move to trash each night, and you get a short Telegram report of what went.

Runs
Daily
Apps
Gmail, Telegram
AI
Yes, uses the built-in AI allowance
Access
Gmail gmail.modify; Telegram bot token

Send this to your assistant

Create a ClickRuntime automation: every night, find promotional emails older than 30 days, have AI double-check they're junk, move them to trash and send me a Telegram summary.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A freelancer's inbox has eleven thousand emails, most of them old sales offers. Search results are cluttered, storage is nearly full, and bulk-deleting feels risky because a receipt or a client invoice might be mixed in.

Clearing promotions older than a month, with a second check on each one, keeps the inbox tidy while the nightly report shows exactly what was removed.

What you get out of it

  • Search results you can use

    With old offers gone, searching your inbox brings up real conversations and receipts instead of pages of sales emails.

  • Storage stays under control

    Removing old promotions regularly keeps your mailbox from filling up and asking you to pay for more space.

  • Receipts and invoices are kept

    Each email gets a second look before it is trashed, so order confirmations and bills that land in Promotions are left alone.

  • You can see what went

    The Telegram report lists the senders that were cleared, and anything trashed can be restored from Gmail's trash for 30 days.

How it works

What happens, step by step

  1. Every night ClickRuntime finds emails in your Promotions category that are older than 30 days.

  2. It skips senders you asked it to keep.

  3. AI looks at each subject and sender and keeps anything that looks like a receipt, invoice or account notice.

  4. The rest are moved to Gmail's trash, and you get a Telegram message with how many were cleared and from whom.

Before it runs live

  • Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
  • Connect Telegram

What you get

RunsDaily
Clear out old promotional emails every nighttoday, 9:00Succeeded
Telegram · Inbox reportCleared 84 old promotions. Top: Acme Outlet (22), Northwind Travel (15). Kept 3 receipts.

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Change what the AI looks for, or how it writes the result
  • Add another app, for example also send it to Slack
  • Combine it with other Gmail and Telegram steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
ai_inbox_clean_up_with_telegram_report.pyexample
from collections import Counter
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from clickruntime import on_trigger, credentials, ai, http

KEEP = ["bank.example", "acme.example"]
CHAT_ID = "your-telegram-chat-id"

@on_trigger
def run(event):
    gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False).users()
    ids = gmail.messages().list(userId="me", q="category:promotions older_than:30d", maxResults=100).execute().get("messages", [])
    rows = []
    for m in ids:
        h = {x["name"]: x["value"] for x in gmail.messages().get(userId="me", id=m["id"], format="metadata", metadataHeaders=["From", "Subject"]).execute()["payload"]["headers"]}
        if not any(k in h.get("From", "") for k in KEEP):
            rows.append((m["id"], h.get("From", ""), h.get("Subject", "")))
    trashed = Counter()
    for i in range(0, len(rows), 25):
        batch = rows[i:i + 25]
        verdict = ai.generate("For each line answer junk or keep (keep receipts, invoices, account notices):\n" +
                              "\n".join(f"{n}. {f} | {s}" for n, (_, f, s) in enumerate(batch, 1)), max_output_tokens=200).text.lower().splitlines()
        for (mid, sender, _), v in zip(batch, verdict):
            if "junk" in v:
                gmail.messages().trash(userId="me", id=mid).execute()
                trashed[sender.split("<")[0].strip()] += 1
    text = f"Cleared {sum(trashed.values())} old promotions. Top: " + ", ".join(f"{s} ({n})" for s, n in trashed.most_common(5))
    http.post(f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}/sendMessage", json={"chat_id": CHAT_ID, "text": text})
    return {"trashed": sum(trashed.values())}

FAQ

Common questions

Are emails deleted permanently?
No. They are moved to Gmail's trash, where Gmail keeps them for 30 days before removing them. You can restore any email in that time.
Can I protect certain senders?
Yes. List senders or domains to keep, such as your bank or a shop you buy from often, and their emails are never trashed.
Can I change the 30-day age?
Yes. Some people prefer 7 days, others 90. Shorter ages clear more but give you less time to use a discount code.
What permissions does it need?
Gmail gmail.modify; Telegram bot token. Nothing else in your accounts is used.
Does it need AI?
Yes. It uses ClickRuntime's built-in AI, so you don't need an OpenAI or Anthropic key. Every plan includes a monthly AI allowance.
How many runs does it use?
One run each time it runs (daily). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Clear out old promotional emails every night” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.