Batch delete thousands of Gmail drafts in seconds
Mail in macOS has long suffered from a bug that can generate thousands of near-duplicate Gmail drafts (the simplest workaround is switching draft storage from server to local).
Selecting more than 50 drafts in the Gmail web interface via "Select all x messages in Drafts" disables the "Discard drafts" option, making large-scale deletion tedious.
A faster alternative is using Google Apps Script. While script executions are limited to 6 minutes, the following API-based method can delete thousands of drafts in seconds:
Go to https://script.google.com → New project
Paste and save the following script:
function deleteAllDrafts_FinalPaginated() { try { let allMessageIds = []; let pageToken; let pageCount = 0; // 1. Loop through all pages of drafts to get every ID. do { const response = Gmail.Users.Drafts.list('me', { maxResults: 500, // Fetch up to 500 per page for speed pageToken: pageToken }); if (response.drafts && response.drafts.length > 0) { const messageIdsOnPage = response.drafts.map(draft => draft.message.id); allMessageIds = allMessageIds.concat(messageIdsOnPage); pageCount++; } // Get the token for the next page. If there isn't one, the loop will end. pageToken = response.nextPageToken; } while (pageToken); const totalDrafts = allMessageIds.length; if (totalDrafts === 0) { Logger.log("No drafts to delete."); return; } Logger.log("Found " + totalDrafts + " drafts across " + pageCount + " page(s). Processing in batches..."); // 2. Process the complete list of IDs in chunks. const batchSize = 100; for (let i = 0; i < totalDrafts; i += batchSize) { const chunk = allMessageIds.slice(i, i + batchSize); const request = { ids: chunk }; Gmail.Users.Messages.batchDelete(request, 'me'); Logger.log("Deleted batch: " + (i + 1) + " through " + Math.min(i + batchSize, totalDrafts)); } Logger.log("Successfully initiated deletion of all " + totalDrafts + " drafts."); } catch (e) { Logger.log("Error deleting drafts: " + e.name + " - " + e.message); } }
In the left-hand menu, click + next to Services
Select Gmail API → Add
Click Run
During testing, used this script to quickly generate 105 drafts:
function createTestDrafts() {
for (var i = 1; i <= 105; i++) {
var subject = "Test Draft " + i;
var body = "This is test draft number " + i + ".\nGenerated for batch deletion testing.";
var recipient = Session.getActiveUser().getEmail();
GmailApp.createDraft(recipient, subject, body);
}
Logger.log("105 test drafts created.");
}
❧ 2025-08-06