Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kulemantu/84682cfebe72eb925cfe to your computer and use it in GitHub Desktop.
Save kulemantu/84682cfebe72eb925cfe to your computer and use it in GitHub Desktop.
A Google Apps Script script to bulk delete large amounts of email in Gmail while avoiding the error #793 which Gmail encounters normally
// This script, when used with Google Apps Scripts will delete 500 emails and can be triggered to run every minute without user interaction enabling you to bulk delete email in Gmail without getting the #793 error from Gmail.
// Configure the search query in the code below to match the type of emails you want to delete
// Browser to https://script.google.com/.
// Start a script and paste in the code below.
// After you past it in, save it and click the little clock looking button. This is for your triggers. You can set up how frequently you want the script to run (I did mine for every minute).
// Source: https://productforums.google.com/d/msg/gmail/YeQVDuPIQzA/kpZPDDj8TXkJ
// Edits: Added functions to make the process more flexible
// Reference here: https://developers.google.com/apps-script/reference/gmail/gmail-app
function deleteFromUserExample() {
processEmail('in:inbox from:user@example.com', 'moveThreadsToTrash');
}
function markReadLabelWork() {
processEmail('label:work', 'markThreadsRead');
}
function markReadFromInfoExample() {
processEmail('from:user@example.com', 'markThreadsRead');
}
function processEmail(search, batchAction) {
var batchSize = 100; // Process up to 100 threads at once
var threads = GmailApp.search(search);
for (j = 0; j < threads.length; j += batchSize) {
GmailApp[batchAction](threads.slice(j, j + batchSize));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment