Skip to content

Instantly share code, notes, and snippets.

@y16ra
Created January 30, 2017 08:21
Show Gist options
  • Save y16ra/5502df325b9e18ba20eafc00b643ca03 to your computer and use it in GitHub Desktop.
Save y16ra/5502df325b9e18ba20eafc00b643ca03 to your computer and use it in GitHub Desktop.
ラベルと保管日数をスプレッドシートで指定して保管日数を超えているメールを削除するGAS
function deleteOldMail() {
var sheet = SpreadsheetApp.getActive().getSheetByName('label');
for(var row=2; row<=sheet.getLastRow(); row++){
var labelName = sheet.getRange(row, 1).getValue();
var days = sheet.getRange(row, 2).getValue();
var deleteThreads = GmailApp.search('older_than:'+days+'d -is:starred label:'+ labelName);
for (var i = 0; i < deleteThreads.length; i++) {
deleteThreads[i].moveToTrash();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment