Skip to content

Instantly share code, notes, and snippets.

@alimbada
Created May 15, 2024 22:41
Show Gist options
  • Save alimbada/5bc5878338ead31b6308ac9fd748baf1 to your computer and use it in GitHub Desktop.
Save alimbada/5bc5878338ead31b6308ac9fd748baf1 to your computer and use it in GitHub Desktop.
Google Apps Script for cleaning up Gmail
function cleanUpGmail() {
var queries = [
'from:([email protected]) in:inbox subject:(from your Steam wishlist on sale) older_than:7d',
'from:([email protected]) in:inbox subject:(is live) older_than:1d',
'from:ebay.com subject:("is live!" OR "has been relisted") older_than:7d',
// Security alerts
'from:([email protected]) in:inbox subject:("Security alert" OR "New sign-in from") older_than:1m',
// 2FA
'from:([email protected]) in:inbox older_than:1d subject:("two-step authentication" )'
]
var threads = Array();
for(var query of queries){
threads.push(...GmailApp.search(query));
}
Logger.log("Cleaning up %s threads", threads.length)
GmailApp.markThreadsRead(threads).moveThreadsToTrash(threads);
}
@alimbada
Copy link
Author

Settings for the trigger

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment