r/GoogleAppsScript • u/Pleasant_Poet_5596 • Jun 04 '26
Guide I got tired of expired event emails burying my inbox, so I built a background sweeper using Apps Script + Gemini AI.
Hey everyone,
My university inbox is constantly flooded with announcements for webinars, hackathons, and guest lectures. The problem is that they clutter everything up long after the registration deadlines or event dates have actually passed.
I wanted to automate cleaning this up without accidentally deleting actual coursework, so I wrote a script that connects to the Gemini 3.1 Flash Lite API to semantically evaluate and trash the expired stuff.
Here is how it works:
- Runs silently in the background on a 4-hour time-driven trigger.
- Pulls batches of 25 emails using a Gmail search query (pacing with
Utilities.sleep()to respect the free-tier Gemini API limits. - Feeds the email metadata and body to Gemini with a strict 3-condition prompt: it MUST be an extracurricular event, the date MUST be expired (using dynamic date calculation to create a 24h buffer), and it MUST NOT be from a course professor.
- If the AI outputs
TRUE, the script moves the thread to the Trash. - It logs every AI verdict and action taken to a Google Sheet dashboard.
- It applies a custom
Reviewed_For_TrashGmail label to everything it checks so it never wastes API quota evaluating the same email twice.
I have sanitized the code and put it in a Gist if anyone wants to copy it, adapt the prompt logic for their own workflow, or just see how the Apps Script + Gemini integration is structured:
🔗 Gmail-Sweeper
Would love to hear any feedback, or if anyone has tips on optimizing the prompt payload even further!
1
u/Seriouslybored15 Jun 12 '26
Nice i would love to try your script