Introduction

Overview

If you plan to be away from your Gmail account—say, a vacation or a place without access to the internet—you can set up a vacation responder in Gmail to automatically notify people that you won’t be able to get back to them right away.

When the autoresponder is active, whenever somebody sends you an email, they’ll receive an email response containing what you’ve written in your vacation auto reply.

That’s all Gmail 101…

But what if you want to reply to your customer even while you are not on vacation?

(Like, for example, when your office is closed).

Well, there is a script that helps you to do that!

Video Tutorial

Setting up the Gmail AUTORESPONDER script

The instructions on this article work for Gmail or G Suite email accounts.

1 – Go to https://www.google.com/script/start/ and click on the ‘Start Scripting‘ button.

2 – Click New Script at the top left.

3 – Rename the project to whatever you want (where you see “Untitled project”) – this will be the app name.

4 –  Replace the code in Code.gs with the code below:

gs

function autoReply() {
  var interval = 5;          //  if the script runs every 5 minutes; change otherwise
  var wkend = [6,0];   // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
  var wkendMessage = "Hi, Thank you for contacting us. The office is now closed.
                     All emails will be attended to when the office re-opens at 9:00am PST on Monday morning.";
  var wkdayMessage = "Hi! Thank you for your email. The office hours are Mondays - Fridays 9-6pm PST. 
                     You are getting this email because it is outside business hours and  we just wanted you to know that we 
                     got your email, and you should expect a reply when we are back in the office, usually in 24-48 hours. 
                     Thank you for your patience!";
  var date = new Date();
  var day = date.getDay();
  var hour = date.getHours();
  if (wkend.indexOf(day) > -1 || (day == 5 && hour >= 18)) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    for (var i = 0; i < threads.length; i++) {
      threads[i].reply(wkendMessage);
    }
  }
  else if (hour < 9 || hour >= 18) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    for (var i = 0; i < threads.length; i++) {
      threads[i].reply(wkdayMessage);
    }
  }
}

5 – Customize the message based on your needs.

The current message is a generic one that is set for offices that work from 09:00AM to 18:00PM.

6 –  Customize the days based on your needs.

The current week day message will be sent from Monday to Friday.

7 – When the customization is completed, click Save and Run.

8 – Then click Publish > Deploy as Web App

9 – Authorize the script with your Gmail Account.

10 – Test the script and verify it works.

Results

Voila! Your after working hours emails will be auto-replied for you!

Using this script will allow you to maintain high levels of customer service!

What do you think of this tutorial?

Article Title: How to set up a Gmail Auto Reply for Office Hours

Short Description: Learn how to set up a Gmail autoresponder that applies to certain parts of the day only.

Author: Ardian Lumi

Publisher - Orgnization: MemberFix

Publisher Logo:

User Review
5 (2 votes)

 

R

Now let’s hear from you!

Are you using this script for your Gmail account?

Is this article helpful for you?

Tell us in the comments section below.

Share This