Add Email Signature to Email Notification Script -


i writing code on google apps script send email every time there new announcement made in site. here code reference:

var url_of_announcements_page = "https://sites.google.com/announcements";  var who_to_email = "emailaccount";  function emailannouncements(){   var page = sitesapp.getpagebyurl(url_of_announcements_page);    if(page.getpagetype() == sitesapp.pagetype.announcements_page){       var announcements = page.getannouncements({ start: 0,                                                max: 10,                                                includedrafts: false,                                                includedeleted: false});     announcements.reverse();                                         for(var in announcements) {        var ann = announcements[i];        var updated = ann.getlastupdated().gettime();        if (updated > propertiesservice.getscriptproperties().getproperty("last-update")){          var options = {};           options.htmlbody = utilities.formatstring("<h1><a href='%s'>%s</a></h1>%s", ann.geturl(), ann.gettitle(), ann.gethtmlcontent());          mailapp.sendemail(who_to_email, "announcement - '"+ann.gettitle()+"'", ann.gettextcontent()+"\n\n"+ann.geturl(), options);          propertiesservice.getscriptproperties().setproperty('last-update',updated);       }     }   } }  function setup(){  propertiesservice.getscriptproperties().setproperty('last-update',new date().gettime()); }   

i know if possible add gmail signature code. when send script signature removed. have make signature in code or able signature gmail , automatically insert @ end? here line formatting of email:

mailapp.sendemail(who_to_email, "announcement - '"+ann.gettitle()+"'", ann.gettextcontent()+"\n\n"+ann.geturl(), options); 

apps script cannot access user's signature: there no method in mailapp, or gmailapp, or in gmail api accessible via advanced google services.

in principle, use gmailapp recent outgoing message , search text signature contained after last -- found in message body. requires giving script lot more access (gmailapp can access, forward , delete existing email, unlike mailapp) , error-prone (when text parsing fails, might end embarrassing fragment of text in message).

just append directly:

var signature = "\n\n--\nfirstname lastname";  // ...  mailapp.sendemail(... +signature, options); 

(by way, gmail web interface , gmail mobile app have different user signatures in general, having 1 script-generated messages doesn't seem unusual.)


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -