Skip to content

Instantly share code, notes, and snippets.

@ershad
Last active April 24, 2020 08:05
Show Gist options
  • Save ershad/ac145b0fce368bdd514b7a17298059b8 to your computer and use it in GitHub Desktop.
Save ershad/ac145b0fce368bdd514b7a17298059b8 to your computer and use it in GitHub Desktop.
function deleteFromGmail(search_query) {
let batchSize = 100;
let threads = GmailApp.search(search_query);
for (slice_index = 0; slice_index < threads.length; slice_index += batchSize) {
GmailApp.moveThreadsToTrash(threads.slice(slice_index, slice_index + batchSize));
}
}
function deleteOldSocialMailsFromGmail() {
// Delete 6 months old Social Emails
deleteFromGmail("category:social older_than:6m")
}
function deleteOldPromotionsMailsFromGmail() {
// Delete 6 months old Promotions Emails
deleteFromGmail("category:promotions older_than:6m")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment