jeffharbert icon

Gmail: Archive 'read' messages in Inbox older than 30 days

jeffharbert | PRO | 02/24/13 06:23:33 PM UTC | 0 ⭐ | 394 👁️ | Never ⏰ | []
text |

590 B

|

None

|

0 👍

/

0 👎

;This Google Apps Script for Gmail archives all 'read' messages in the Inbox
;that are older than 30 days
 function checkRead() {
var delayDays = 30 // Enter # of days before read messages are archived
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays);
var threads = GmailApp.getInboxThreads();
  for ( var i = 0 ; i < threads.length; i++){
    var checkread = threads[i].isUnread();
 if (threads[i].getLastMessageDate()<maxDate){
   if ( checkread == false )
   {
   Logger.log(threads[i].getLastMessageDate());
   GmailApp.moveThreadToArchive(threads[i])
   }
}
}
}

Comments