title: Sending an Email Notification from Google Sites
body: <p>I've been trying to set up an email notification for when I create a new announcement in my google site. I used a base code I found online but it isn't working for me. Here it is:</p>
  
  <pre><code>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 i in announcements) { 
        var ann = announcements[i]; 
        var updated = ann.getLastUpdated().getTime(); 
        if (updated &gt; ScriptProperties.getProperty('last-update')){ 
          var options = {}; 
  
          options.htmlBody = Utilities.formatString("&lt;h1&gt;&lt;a href='%s'&gt;%s&lt;/a&gt;&lt;/h1&gt;%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());
  }
  } 
  </code></pre>
  
  <p>The code seems to run with out any error message appearing. However, I do not receive the emails on the account I write in the code. I have given full permission so that the script can send the email from my account. It just doesn't seem to fulfil the task needed.</p>
  
  <p>The google site I am using to write the announcements is still private and only I can see it, does that play a role in this code not working?</p>
  
  <p>If you see any mistakes or have any idea what the issue is I would be happy to know.</p>