This post first appeared on pygaze.org 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.
- Go to gmail.com and log into your account (email@example.com).
- Go to script.google.com. You should be automatically logged in if you did step 1.
- Open a new script: File -> New -> Script file. Call it autoreply.js.
- Paste the following code into your script, and make sure to change the email addresses to match your own:
- 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 firstname.lastname@example.org. If it finds any unread emails to email@example.com, it will automatically send them a reply (from firstname.lastname@example.org), 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.