Hide and Show mails automatically after x days in Gmail - Easy steps

Now Gmail lets you to snooze a mail for some days.. i.e., You can temporarily hide a mail from inbox view than make it shown automatically after few days.

Some times, we receive a mail which we want read again after some days, in such times we have to set a remainder or anything else.

But, now we can use Gmail Snooze setup with apps script. 

For example we can hide a mail from inbox (by applying a label to archive), and it will be automatically shown after 7 days in inbox.

Step 1:-

Login  to your Gmail

Step 2:-

Open Google Docs

Step 3:-

Create New > SpreadSheet

Step 4:-

Tools > Script Editor

Step 5:-

Paste the following script

 
var MARK_UNREAD = false;
var ADD_UNSNOOZED_LABEL = false;
 
function getLabelName(i) {
  return "Snooze/Snooze " + i + " days";
}
 
function setup() {
  // Create the labels we’ll need for snoozing
  GmailApp.createLabel("Snooze");
  for (var i = 1; i <= 7; ++i) {
    GmailApp.createLabel(getLabelName(i));
  }
  if (ADD_UNSNOOZED_LABEL) {
    GmailApp.createLabel("Unsnoozed");
  }
}
 
functio
n moveSnoozes() {
  var oldLabel, newLabel, page;
  for (var i = 1; i <= 7; ++i) {
    newLabel = oldLabel;
    oldLabel = GmailApp.getUserLabelByName(getLabelName(i));
    page = null;
    // Get threads in "pages" of 100 at a time
    while(!page || page.length == 100) {
      page = oldLabel.getThreads(0, 100);
      if (page.length > 0) {
        if (newLabel) {
      
    // Move the threads into "today’s" label
          newLabel.addToThreads(page);
        } else {
          // Unless it’s time to unsnooze it
          GmailApp.moveThreadsToInbox(page);
          if (MARK_UNREAD) {
            GmailApp.markThreadsUnread(page);
          }
          if (ADD_UNSNOOZED_LABEL) {
      
      GmailApp.getUserLabelByName("Unsnoozed")
              .a
ddToThreads(page);
          }          
        }     
        // Move the threads out of "yesterday’s" label
        oldLabel.removeFromThreads(page);
      }  
    }
  }
}

 

Step 6:-

Click Save button, and give a script name For ex. "gmailsnooze"

Step 7:-

 In the dropdown labeled "Select a function to run," choose "setup" and click the blue run arrow to the left of it. 

 This will ask you to authorize the script, and will create the necessary labels in your Gmail. 

Step 8:-

Triggers > Current Script's triggers

Click the link to set up a new trigger, choosing the "moveSnoozes" function, a "time-driven" event, "day timer," and then "midnight to 1am."

Click save button

Step 8:-

Now run the script again, that's all you are done.

 Now you can access the label under Move to > > button right from your Gmail Inbox

 

 

 

 

 

 

Source : GmailBlog

Category: