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.
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
Every night ClickRuntime finds emails in your Promotions category that are older than 30 days.
It skips senders you asked it to keep.
AI looks at each subject and sender and keeps anything that looks like a receipt, invoice or account notice.
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
Build your own
Need it to work differently?
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
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?
Can I protect certain senders?
Can I change the 30-day age?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
Get a morning newsletter digest on Telegram
Yesterday's newsletters arrive as one short digest on Telegram at 7am, as text or a voice message.
See how it worksGet new videos from your favourite YouTube channels with AI summaries
New videos from the channels you follow arrive on Telegram and by email, each with a short summary so you know which to watch.
See how it worksMonitor your sites and SSL certificates with Telegram alerts
Your websites are checked every 5 minutes and their certificates daily, and you hear on Telegram and by email when something is wrong.
See how it worksKeep exploring
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.