Guest User

Delete Me

a guest
Nov 20th, 2013
1,657
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function auto_delete_mails() {
  2. var label = GmailApp.getUserLabelByName("Delete Me");
  3. if(label == null){
  4. GmailApp.createLabel('Delete Me');
  5. }
  6. else{
  7. var delayDays = 2 // Enter # of days before messages are moved to trash
  8. var maxDate = new Date();
  9. maxDate.setDate(maxDate.getDate()-delayDays);
  10. var threads = label.getThreads();
  11. for (var i = 0; i < threads.length; i++) {
  12. if (threads[i].getLastMessageDate()<maxDate){
  13. threads[i].moveToTrash();
  14. }
  15. }
  16. }
  17. }
RAW Paste Data