The following script is supposed to use to send automatic response emails using Gmail's canned response feature while avoiding “+canned.response” added to the username in the reply:
function RespondEmail(e) {
// set response mail
var response = GmailApp.getMessageById('153c2b9e7d4ac8c4');
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);
}
The script can be set to search for emails by setting a time based interval trigger. If an email with the label respondemail
is found, which could have been assigned to it through the Gmail filter feature, an automatic answer will be sent.
However, no alias is picked up (aliases
is just an empty string). It works inserting an email address instead of this string, though. Is it possible to have your name shown as sender, instead of just your email address, which will happen when you send an email manually?
1452e6aef2c5c09f
? To get the Id of a message that is the first in a thread, open it in Gmail: the Id is the part at the end of URL, after/#inbox/