Automatically Snooze Incoming Mail in Gmail


I get emails every day for a friend’s project that I want to respond to at least 12 hours after I get them, to see if the user has any questions. I was thinking it would be nice if there was a feature for this in Gmail. There isn’t in Gmail itself, but I figured there has to be another way.

I found a code snippet provided by the Gmail team in 2011 for just this purpose. It worked, but threw an error so I reduced it to just the code needed to automatically snooze incoming emails with the “Snooze For 1 Day” label for one day then move them to the inbox.

function setup() {
  // Create the labels we’ll need for snoozing
  GmailApp.createLabel("Snooze");
  GmailApp.createLabel("Snooze/Snooze 1 days");
  if (ADD_UNSNOOZED_LABEL) {
    GmailApp.createLabel("Unsnoozed");
  }
}

function moveSnoozes() {
 // This code will move the email from the "Snooze 1 day" label to the inbox.
  var oldLabel, page;
    oldLabel = GmailApp.getUserLabelByName("Snooze 1 day");
    page = null;
    // Get threads in "pages" of 100 at a time
    while(!page || page.length == 100) {
      page = oldLabel.getThreads(0, 100);
      GmailApp.moveThreadsToInbox(page);
        // Move the threads out of "yesterday’s" label
      oldLabel.removeFromThreads(page);
      }  
    }

Hop over to https://script.google.com/home and hit “New script”. You will then want to name the project and paste in the code from above. Read the comments to know what the code is doing. Then save the file using File > SaveClick on “Select Function”, then “setup”. Then click the arrow to run the setup function. It will prompt you to allow your script to access your email. You will need to allow it in order to continue. Once that is done, you’ll want to setup a trigger. More here: https://gmail.googleblog.com/2011/07/gmail-snooze-with-apps-script.html

You can then setup filters to automatically apply the “Snooze for 1 day” label to new mail from a specific sender: https://www.nytimes.com/2017/01/03/technology/personaltech/how-to-automatically-label-new-gmail-messages.html

Then we’re done! We have automatic snoozing of new emails.


2 responses to “Automatically Snooze Incoming Mail in Gmail”

  1. This is super helpful, thanks Josh! I made a few edits to the code here that i thought i’d pass along:

    – I removed the “if (ADD_UNSNOOZED_LABEL)…” section from setup(), since the variable ADD_UNSNOOZED_LABEL doesn’t exist in the pared-down version of the code you shared (and the Unsnoozed label doesn’t get used anywhere else in the code).
    – I edited the second line of setup() to read “GmailApp.createLabel(“Snooze/Snooze 1 day”);” (rather than “days”) so that the name of the created label would match the one used later in the code.
    – I changed the line “oldLabel = GmailApp.getUserLabelByName(“Snooze 1 day”);” in moveSnoozes() to read “oldLabel = GmailApp.getUserLabelByName(“Snooze/Snooze 1 day”);”, again to match the full name of the label (it was throwing an error for me otherwise).

    Have a great one!

    All the best,
    Dan

Leave a Reply