Selective gmail auto-reply

This post first appeared on in June 2015.

In Gmail, you can set a vacation responder, which is great for automatic replies. However, if you have more than one address linked to your account, you cannot set the vacation responder to reply specifically to emails that were sent to one of your addresses only.

This is problematic for me. I have two work email addresses, two developer addresses, and of course my personal one. And everything feeds into the same Gmail inbox! When I go on vacation, I want to set an automatic reply to work-related email, but I don’t want that same message go out to my personal email! Another issue occurred when I changed jobs: my former email address will stop working at some point, so I want to set an auto-reply for that address that tells people to update to my new address.

To solve these problems, I had two options. I could get my life together: Having everything come into one inbox seems to be a very disorganised way of doing stuff, and I should find a better way. Or I could stick with my bad habit, and instead hack my way to a temporary patch. Obviously, I chose the latter.

I found the solution in Google Script, which allows you to set up some JavaScript code to be run periodically. Suppose you change jobs: Your old email is and will be deactivated in a few weeks. Your new work address is, and both work addresses are synced with your Gmail ( You want people that send messages to your old address to receive an automatic reply that tells them to send their email to your new address instead. Here’s how to do it:

  1. Go to and log into your account (
  2. Go to You should be automatically logged in if you did step 1.
  3. Open a new script: File -> New -> Script file. Call it autoreply.js.
  4. Paste the following code into your script, and make sure to change the email addresses to match your own:
  5. Set a timer, to have your script run automatically every now and again. Go to Resources -> Current project’s triggers -> Add a new trigger. Set RespondEmail to Time-driven, Minute timer, Every minute.

The script will now run every minute, and check if there are any unread emails to If it finds any unread emails to, it will automatically send them a reply (from, and will then mark the message as read. Easy!

Now you don’t have to manually reply to all those people using your old email, or to people that send you work-related messages while you’re on holiday.

Leave a Reply

Your email address will not be published. Required fields are marked *