Sending an Email Notification from Google Sites -
i've been trying set email notification when create new announcement in google site. used base code found online isn't working me. here is:
function myfunction() { var url_of_announcements_page = "https://sites.google.com/announcements-page-link"; var who_to_email = "name@company.com" 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 > scriptproperties.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); scriptproperties.setproperty('last-update',updated); } } } } function setup(){ scriptproperties.setproperty('last-update',new date().gettime()); } } the code seems run out error message appearing. however, not receive emails on account write in code. have given full permission script can send email account. doesn't seem fulfil task needed.
the google site using write announcements still private , can see it, play role in code not working?
if see mistakes or have idea issue happy know.
you have written both functions under myfunction. need write separately. scriptproperties api deprecated, use propertiesservice. refer below code. hope helps!
var url_of_announcements_page = "https://sites.google.com/announcements-page-link"; var who_to_email = session.getactiveuser().getemail(); 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()); }
Comments
Post a Comment