Skip to content

Instantly share code, notes, and snippets.

@sreejithpro
Last active March 15, 2023 16:00
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 sreejithpro/27cbd33502aa5f7880f91c1ac4cba822 to your computer and use it in GitHub Desktop.
Save sreejithpro/27cbd33502aa5f7880f91c1ac4cba822 to your computer and use it in GitHub Desktop.
Search for read email with sender and subject from a google doc and delete them
function deleteEmails() {
var sheet = SpreadsheetApp.openById('SHEET ID').getSheetByName('Sheet1');
var data = sheet.getDataRange().getValues();
for (var i = 1; i < data.length; i++) {
var sender = data[i][0];
var subject = data[i][1];
var threads = GmailApp.search('is:read from:' + sender + ' subject:' + subject);
Logger.log('Deleted' + i + ' emails')
for (var j = 0; j < threads.length; j++) {
threads[j].moveToTrash();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment