Skip to content
NEWMarketplace and your team: sell what you build, and get plans and changes that are tested before you see them. See what is new

Library / Email Automation

Email Automation

Sweep unread Gmail junk to Spam with GPT-5 and Telegram undo

Daily or on demand, skips anyone you have emailed, has GPT-5 classify unknown senders, moves only high-confidence junk to Spam, and offers a Telegram undo.

What it does

## Sweep unread Gmail junk to Spam with GPT-5 and a Telegram undo button ### How it works 1. Runs on a daily schedule, or on demand from a Telegram message. 2. Reads your unread inbox, then reads your sent mail to build a list of people you actually correspond with. 3. Anyone you have written to is removed before any model call, so known contacts can never be swept. 4. GPT-5 judges only the remaining unknown senders and returns a verdict with a confidence level for each. 5. Only high confidence junk is moved. Anything borderline stays in your inbox and is counted in the report. 6. The undo record is written BEFORE anything moves, so a failure later still leaves the mail recoverable. 7. Matching mail is moved to Spam through the Gmail API, removing the inbox and unread labels. 8. Telegram gets a list of what moved and why, with a single button that puts every message back. 9. Each run is logged to a Google Sheet, including the quiet runs where nothing matched. ### Setup steps - [ ] Create a Telegram bot with @BotFather and add the token as a Telegram credential. - [ ] Add a Gmail OAuth2 credential. The workflow needs permission to read and modify labels. - [ ] Add an OpenAI credential for the classifier. - [ ] Add a Google Sheets credential, then pick a spreadsheet and tab in both Log nodes. - [ ] Set admin_chat_id in the Config node so the scheduled run knows where to send. - [ ] Run it once manually and check what it would move before trusting the schedule. ### Customization inbox_query is a normal Gmail search string. Narrow or widen what gets considered. max_moves_per_run caps how much a single run can move, so a bad day stays small. undo_window_days controls how long an undo batch stays available. Gmail deletes spam after 30 days regardless. sent_lookback decides how far back the contact protection looks. A longer window protects more people. The confidence bar is in the Resolve Junk node. It only accepts high confidence; loosening it will move more mail. Change the schedule, or delete that trigger if you only want to sweep on demand.

The steps

  1. Daily Sweep 05:30
  2. Telegram Trigger
  3. ⚙️ Config
  4. Normalise Entry
  5. Route by Action
  6. Prep Sweep Input
  7. Fetch Inbox
  8. Fetch Sent Contacts
  9. Build Junk Payload
  10. Classify Junk
  11. Resolve Junk
  12. Any junk?
  13. Stash Undo
  14. Move to Spam

30 steps in total.

Similar automations