Created
January 30, 2017 08:21
-
-
Save y16ra/5502df325b9e18ba20eafc00b643ca03 to your computer and use it in GitHub Desktop.
ラベルと保管日数をスプレッドシートで指定して保管日数を超えているメールを削除するGAS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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