Skip to content

Instantly share code, notes, and snippets.

@bo33b
Created February 13, 2025 06:22
Show Gist options
  • Save bo33b/52a853cbf48f9d663f8b139402e5a5e2 to your computer and use it in GitHub Desktop.
Save bo33b/52a853cbf48f9d663f8b139402e5a5e2 to your computer and use it in GitHub Desktop.
Google Apps Script that archives all labeled messages in the Gmail inbox after 2 days
function gmailAutoarchive() {
// Build the query
var query = "in:inbox is:read has:userlabels older_than:2d";
// Get the threads
var threads = GmailApp.search(query);
// Archive the threads
for (var thread of threads) thread.moveToArchive();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment