12

If I set up a filter and send it a canned response, Gmail appends +canned.response to my username in the reply.

For example, given the filter "from:[email protected] to:[email protected]" set up to send a canned response, when [email protected] sends me an email the canned response comes from [email protected] instead of [email protected], exposing that I'm using a canned response.

Is there a way to avoid this?

1
  • 4
    There's certainly nothing in Gmail's settings that control that. I have a feeling the answer is "No". Remember too: This is (currently) a Lab feature and is not fully supported.
    – ale
    Commented Sep 5, 2013 at 15:25

3 Answers 3

3

The thing to remember about the current "canned response" for Gmail is that it has to be added from the "Labs" tab.

This means that there may be sparse support and has potential to completely disappear. This particular "Lab" has a number of other quirks that are outside the scope of your question but I believe your answer is "No".

It appears that the reason for the "+canned.response" is to prevent some email loop that someone might inadvertently create by having the message resent to themselves or even just replied to.

In my test I used a filter for the response based on a specific "From" with a "Subject" containing a keyword. The canned response fired every time except when I replied directly to the canned response.

I'm sure that most people can live with this quirk, but some of the other quirks I came across in testing this out might cause Google to pull this Lab.

2

I thought of a way to not use the canned response as such (including the added response quote in the email address), but to simply forward the canned response to the filtered emails (recipients). This is how it looks like:

Code

function doGet(e) {
  // retrieve Id's from canned response  
  var drafts = GmailApp.getDraftMessages();
  for(var i in drafts) {
    Logger.log(drafts[i].getId() + " " + drafts[i].getSubject());
  }

  // set canned response mail
  var canned = GmailApp.getMessageById('1410f11ab42ca12d');

  // get all messages
  var eMails = GmailApp.getMessagesForThreads(
    GmailApp.search("label:cannedresponse label:unread"))
      .reduce(function(a, b) {return a.concat(b);})
      .map(function(eMails) {
    return eMails.getFrom() 
  });

  // sort and filter for unique entries  
  var aEmails = eMails.sort().filter(function(el,j,a)
    {if(j==a.indexOf(el))return 1;return 0}); 

  // forward canned response
  for(var j in aEmails) {
    canned.forward(aEmails[j]);
  }

  // mark all as read
  var threads = GmailApp.search("label:cannedresponse label:unread");
  GmailApp.markThreadsRead(threads);    
}

Explained

The first lines are to determine the Id of the canned response you want to send out. The Logger function will help to log all draf Id's. Add this one particular Id into the getMessageById(Id). The next three snippets will get all unread mails from the cannedResponse label and remove duplicates.
Based on the emails present, the canned responses are forwarded to the different recipients. After that, all unread emails in the cannedResponse label are marked as read.

Usage

Add the code by surfing to the following URL: https://script.google.com.
Make sure to press the "bug" button to authenticate the script and its usage. The script can be triggered on a time based interval. Set the trigger in the Resources menu, the way you like.
enter image description here

In this case, there are some prerequisites. You need to have a label called cannedResponse and to have a canned response as draft. Furthermore, a filter needs to be in place, in order to send out canned responses.

Screenshot

enter image description here

2

Jacob,

Your code was just what I was looking for. But being the perfectionist that I am, I found a few issues with your code:

  • The emails sent out are forwarded instead of replied to. This adds a "Fwd:" into the subject line and probably raises a few eyebrows on the receiver's end.
  • I use Gmail to check my (non-Gmail) work email. Your code doesn't work well with this. It replies to my work email with my Gmail address, which will raise even more eyebrows on the receiver's end.
  • Your setup requires a constant email in my drafts folder. That would drive me crazy.

I modified your code to account for these and here is my version:

function RespondEmail(e) {

  // set response mail
  var response = GmailApp.getMessageById('1452e6aef2c5c09f');
  var responsebody = response.getBody();

  //send response email
  var aliases = GmailApp.getAliases()
  var threads = GmailApp.search("label:respondemail label:unread");
  for (var i = 0; i < threads.length; i++) {
    threads[i].reply("", {htmlBody: responsebody, from: aliases[0]});}

  // mark all as read
  var threads = GmailApp.search("label:respondemail label:unread");
  GmailApp.markThreadsRead(threads);
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.