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.
Thanks for the write-up, really appreciate. I am trying to modify this so that it works as an auto-reply that runs every minute from 6pm to 8am every day but I believe I have to write a trigger to achieve this.
Would you have any tips?
Very good question! I’m currently working on a periodic auto-mailer (e.g. to remind lazy co-authors). I’ll include a period auto-reply in there too, as per your request.
I’m trying to figure out a way of having an out of office hours (including weekends) autoresponder.
I would love to know if you managed to write the auto-mailer scheduler, and if you would be willing to share the script.
This script is not working, it is not sending reply to the sender. It is sending email to me as the script says
//send response email
var threads = GmailApp.search(“to:(email@example.com) label:unread”);
How to replace my email ID with receivers email ID?
You copied the bit of code that does a search for all messages that are directed to your mail address (line 7). The reply happens in lines 8-9 (specifically in line 9; line 8 just loops through all emails found by the search in line 7). The script works, because it uses the reply function. The only way in which it’ll send an email to you, is if it’s replying to an email that you sent. (Which you might have done to test it?)
Thank you for sharing this script it is exactly what I had been looking for and works perfectly.
Hi! would you mind sharing the script you used to set up times to auto reply?
Stopped working with Mailchimp beamed campaigns Oct 2018, you need to add the reply to email address on line 9 between the “”.
just wanted to say thank you very much!
Hi, this was working perfectly up until about two weeks ago, it now sends the reply back to me, I have changed nothing so I assume it must be a Gmail change. I use it to reply to a Mailchimp beamed campaign, is there a way of specifying the reply to email to see if this is the problem.
If you do not specify a “reply to” address in the call to threads.reply, it may reply to the “Return-Path:” in the email envelope header, which may be different than the “From:” or “Reply-to:” address in the message header.
Thanks for the addition!
Hi, I am trying to set up an auto reply to run from Monday to Friday between 17:00 to 08:00 and all day Saturdays & Sundays. I thought i done it, but apparantly not! Would you mind offering your thoughts on how to achieve this.
My question is: is it possible to only reply to unread, new mail adresses? If you have a conversation with like a “known” sender, can the script mark that adress as “known sender” and doesnt automatically reply to new mails from that sender?
Like: Only reply to the “first ever email” that somebody sent to me.
That’d be great!
Good question! I suppose there are two potential ways of doing this: 1) Use the gmail API to check whether any emails exist in your inbox or any other folder of the new sender. Downside: computationally expensive if you have many emails, and also misidentifies senders as “new” if you’ve deleted all previous communication. 2) Maintain a list of all sender (in whatever format; could be as text file, database entries, or even by adding all new senders to your Contacts), and check any new email against that.
Can we not add a new label for a new sender_mail like “known sender” with your script? And if another mail is coming, it will see it as “known sender” 😛
Is there a way to include an attachment? I want the auto reply to include a PDF attachment.
Pingback: Selective gmail auto-reply – Quantitative Exploration of Development (Q.E.D.)