In a personal technology column for Android Police, Android Police reported that a user has detailed a method for automatically clearing obsolete bank alerts and one-time passcodes from personal Gmail accounts using a custom Google Apps Script.
Why Standard Gmail Filters Fail at Scheduled Auto-Deletion
Personal Gmail accounts lack a native setting to automatically delete messages based purely on age. While enterprise Google Workspace administrators enjoy policy-level retention controls, personal Gmail users are left without a native setting to delete messages based purely on their age. Users typically attempt to solve this clutter by building advanced search filters. However, standard Gmail filters evaluate incoming mail only at the exact moment of delivery and never inspect those messages again. Applying the older_than search operator to a filter catches existing items once but fails to dynamically execute in the background as future emails age.
Building a Google Apps Script to Trash Old Passcodes
The self-cleaning setup requires a two-step configuration involving a Gmail label and an automated script. First, users create a label named auto-trash alongside a filter matching specific alert subjects. Next, a project is established at script.google.com to run a daily time-driven function. The underlying script searches for labeled threads older than a designated number of days while explicitly excluding starred conversations to protect important messages.
Safeguards and Execution Limits in Personal Inboxes
The script incorporates several guardrails to prevent accidental data loss. Setting a variable called DRY_RUN to true permits a test run that logs matching dates and subjects to the console without actually deleting anything. Furthermore, each execution caps batch processing at 100 threads, matching Gmail’s native trash limit. Trashed items remain safely recoverable in the Trash folder for 30 days before permanent deletion occurs. During the initial trial period, the automation successfully purged approximately 300 old alerts, leaving a consistent rotation of 10 to 15 active messages in the inbox.
Frequently Asked Questions About Gmail Automation
Why can’t standard Gmail filters delete emails after a set number of days?
Gmail filters evaluate messages only at the precise moment of arrival and cannot dynamically track message age over time in personal accounts.

How does the Google Apps Script prevent important emails from being accidentally deleted?
The script explicitly includes a negative search operator that excludes starred threads and restricts operations to a single designated label.
What happens to the messages after the script moves them to the Trash folder?
Trashed messages remain recoverable in the Trash directory for 30 days before Google purges them permanently.
Worth a look