Create a gist now

Instantly share code, notes, and snippets.

ラベルと保管日数をスプレッドシートで指定して保管日数を超えているメールを削除する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