是否可以为在Google网站上发布的任何新公告创建电子邮件通知?发送电子邮件通知在Google网站上发布新公告
当我创建新的公告时,我希望将它发送给所有在邮件列表中注册的人员。如果可能的话,有什么最好的选择?我应该使用Google应用程序脚本还是使用其他服务?
这是一个我在网上发现了谷歌应用程序脚本,但它似乎没有工作:
function myFunction() {
var url_of_announcements_page = "https://sites.google.com/announcements-page-link";
var who_to_email = "[email protected]"
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 i 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());
}
}
编辑:我会定期检查这个问题,看到的最好的答案,希望能帮助别人这需要在他们的网站上有这样一个选项。