title: How to create an email template in Gmail that sends a summary of the upcoming week to multiple email addresses
body: <p>I have a Google Calendar set up for industry events for my co-workers, and I'd like to send a weekly email (through Gmail) that summarizes the following week's events in this Google Calendar. I'm comfortable creating the visual template and setting it up to auto-send weekly, but I need help pulling in the Google Calendar info. </p>
  
  <p>I looked into plug-ins for this, but I can't use them on my work email.</p>
  
  <p>I found code for displaying Google Calendar event info on a website, but I haven't used a public apiKey or a web app client Id before. I'm wary about using them for security reasons because this is for my work email—I'm not confident in setting this up securely.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
  &lt;body bgcolor="black" text="white" link="#00ffff" vlink="green" alink="yellow"&gt;
  &lt;script&gt;
      
  var clientId = 'YOUR_CLIENT_ID HERE'; //choose web app client Id, redirect URI and Javascript origin set to http://localhost
  var apiKey = 'YOUR_APIKEY_HERE'; //choose public apiKey, any IP allowed (leave blank the allowed IP boxes in Google Dev Console)
  var userEmail = "YOUR_ADDRESS@gmail.com"; //your calendar Id
  var userTimeZone = "YOUR_TIME_ZONE_HERE"; //example "Rome" "Los_Angeles" ecc...
  var maxRows = 10; //events to shown
  var calName = "YOUR CALENDAR NAME"; //name of calendar (write what you want, doesn't matter)
      
  var scopes = 'https://www.googleapis.com/auth/calendar';
      
  //--------------------- Add a 0 to numbers
  function padNum(num) {
      if (num &lt;= 9) {
          return "0" + num;
      }
      return num;
  }
  //--------------------- end    
      
  //--------------------- From 24h to Am/Pm
  function AmPm(num) {
      if (num &lt;= 12) { return "am " + num; }
      return "pm " + padNum(num - 12);
  }
  //--------------------- end    
  
  //--------------------- num Month to String
  function monthString(num) {
           if (num === "01") { return "JAN"; } 
      else if (num === "02") { return "FEB"; } 
      else if (num === "03") { return "MAR"; } 
      else if (num === "04") { return "APR"; } 
      else if (num === "05") { return "MAJ"; } 
      else if (num === "06") { return "JUN"; } 
      else if (num === "07") { return "JUL"; } 
      else if (num === "08") { return "AUG"; } 
      else if (num === "09") { return "SEP"; } 
      else if (num === "10") { return "OCT"; } 
      else if (num === "11") { return "NOV"; } 
      else if (num === "12") { return "DEC"; }
  }
  //--------------------- end
  
  //--------------------- from num to day of week
  function dayString(num){
           if (num == "1") { return "mon" }
      else if (num == "2") { return "tue" }
      else if (num == "3") { return "wed" }
      else if (num == "4") { return "thu" }
      else if (num == "5") { return "fri" }
      else if (num == "6") { return "sat" }
      else if (num == "0") { return "sun" }
  }
  //--------------------- end
  
  //--------------------- client CALL
  function handleClientLoad() {
      gapi.client.setApiKey(apiKey);
      checkAuth();
  }
  //--------------------- end
  
  //--------------------- check Auth
  function checkAuth() {
      gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
  }
  //--------------------- end
  
  //--------------------- handle result and make CALL
  function handleAuthResult(authResult) {
      if (authResult) {
          makeApiCall();
      }
  }
  //--------------------- end
  
  //--------------------- API CALL itself
  function makeApiCall() {
      var today = new Date(); //today date
      gapi.client.load('calendar', 'v3', function () {
          var request = gapi.client.calendar.events.list({
              'calendarId' : userEmail,
              'timeZone' : userTimeZone, 
              'singleEvents': true, 
              'timeMin': today.toISOString(), //gathers only events not happened yet
              'maxResults': maxRows, 
              'orderBy': 'startTime'});
      request.execute(function (resp) {
              for (var i = 0; i &lt; resp.items.length; i++) {
                  var li = document.createElement('li');
                  var item = resp.items[i];
                  var classes = [];
                  var allDay = item.start.date? true : false;
                  var startDT = allDay ? item.start.date : item.start.dateTime;
                  var dateTime = startDT.split("T"); //split date from time
                  var date = dateTime[0].split("-"); //split yyyy mm dd
                  var startYear = date[0];
                  var startMonth = monthString(date[1]);
                  var startDay = date[2];
                  var startDateISO = new Date(startMonth + " " + startDay + ", " + startYear + " 00:00:00");
                  var startDayWeek = dayString(startDateISO.getDay());
                  if( allDay == true){ //change this to match your needs
                      var str = [
                      '&lt;font size="4" face="courier"&gt;',
                      startDayWeek, ' ',
                      startMonth, ' ',
                      startDay, ' ',
                      startYear, '&lt;/font&gt;&lt;font size="5" face="courier"&gt; @ ', item.summary , '&lt;/font&gt;&lt;br&gt;&lt;br&gt;'
                      ];
                  }
                  else{
                      var time = dateTime[1].split(":"); //split hh ss etc...
                      var startHour = AmPm(time[0]);
                      var startMin = time[1];
                      var str = [ //change this to match your needs
                          '&lt;font size="4" face="courier"&gt;',
                          startDayWeek, ' ',
                          startMonth, ' ',
                          startDay, ' ',
                          startYear, ' - ',
                          startHour, ':', startMin, '&lt;/font&gt;&lt;font size="5" face="courier"&gt; @ ', item.summary , '&lt;/font&gt;&lt;br&gt;&lt;br&gt;'
                          ];
                  }
                  li.innerHTML = str.join('');
                  li.setAttribute('class', classes.join(' '));
                  document.getElementById('events').appendChild(li);
              }
          document.getElementById('updated').innerHTML = "updated " + today;
          document.getElementById('calendar').innerHTML = calName;
          });
      });
  }
  //--------------------- end
  &lt;/script&gt;
  &lt;script src='https://apis.google.com/js/client.js?onload=handleClientLoad'&gt;&lt;/script&gt;
      &lt;div id='content'&gt;
      &lt;h1 id='calendar' style="color:grey"&gt;LOADING . . . .&lt;/h1&gt;
      &lt;ul id='events'&gt;&lt;/ul&gt;
      &lt;/div&gt;
      &lt;p id='updated' style="font-size:12; color:grey"&gt;updating . . . . .&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This almost solves my problem, but I'm wondering if I can avoid using "var clientId" and "var apiKey" if I'm sending the email from the email address associated with the calendar I'm pulling info from? Or is there a resource that explains how to securely use this code?</p>