/*! Canned Responses (as Forwarding and the Vacation Responder) only apply to new, incoming messages that arrive through SMTP (directly send to Gmail), not to messages fetched through POP3. But with some filters and labels and Apps Script we can! How does it work: - create a top label like 'Canned responses' next, for every automated/canned response: - create a message to be used as response and add a new label below the top label, like 'stop mailing me' - create a filter as you like that adds the desired label to the incoming messages This script will than look for any labeled messages and reply them with the appropriate response. To make the script look for new messages every minute: Go to Google Docs and create a new spreadsheet. Choose "Script Editor" from the "Tools" menu. Remove the dummy code and paste this code. Then click the "Save" button and give it a name. In the dropdown labeled "Select a function to run", choose "setup" and click the run arrow to the left of it. This will ask you to authorize the script, and will create the top label with the example sub label in your Gmail. Then go to the "Resources" menu and choose "Current project's triggers". Click the link to set up a new trigger, choosing the "mailCannedResponse" function, a "Time-driven" event, "Minutes timer", and then "Every minute". Click save and you’re done. For more info, see http://gmailblog.blogspot.nl/2008/10/new-in-labs-canned-responses.html */ // the main label for canned responses, add this label manually or via the // the setup function and add any custom labels below this label var LABEL_PREFIX = 'Canned responses'; // if set to true, send the email from a generic no-reply email address to // discourage recipients from responding to emails var ADD_NO_REPLY = true; // if set to true, the message is moved to the archive after the response // is sent var MOVE_TO_ARCHIVE = true; /* No need to change anything beyond this point... but go ahead, have a look ;-) */ function mailCannedResponse() { var labels = GmailApp.getUserLabels(); // find the labels that start with the given prefix for canned responses... for (var l = 0; l < labels.length; l++) { var label = labels[l]; if (label.getName().indexOf(LABEL_PREFIX+'/') != -1) { // found label... Logger.log(label.getName()); threads = label.getThreads(); Logger.log('# of threads: '+threads.length); // if threads with this label, than... if (threads.length) { // get the response message from the drafts: // it is the one with the same label var drafts = GmailApp.getDraftMessages(); var response = null; for (var d = 0; d < drafts.length; d++) { var labels = drafts[d].getThread().getLabels(); for (var ll = 0; ll < labels.length; ll++) { if (labels[ll].getName() == label.getName()) { response = drafts[d]; continue; } } if (response) continue; } // if response message found, send it to each thread and remove label if (response) { for (var t = 0; t < threads.length; t++) { var thread = threads[t]; // only the threads in inbox, thus skipping the draft/response itself if (thread.isInInbox()) { Logger.log('thread: '+thread.getFirstMessageSubject()); thread.reply(response.getPlainBody(), { htmlBody: response.getBody(), noReply: ADD_NO_REPLY }); thread.removeLabel(label); // response send, remove label... if (MOVE_TO_ARCHIVE) thread.moveToArchive(); } } } } } } } // create the top label and a sub label as an example function setup() { GmailApp.createLabel(LABEL_PREFIX); GmailApp.createLabel(LABEL_PREFIX+'/stop mailing me'); }