Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Google Apps Script mashup to send free SMS notifications using Google Calendar guest invite feature
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
// Usage - have a column titled username with recipient google account email addresses.
// Guests need to enable SMS notifications on invites in their own Google Calendar.
// More info
function sendSMSviaCalendarGuest(){
var cal = CalendarApp.getDefaultCalendar(); // get default calendar - could also use CalendarApp.getCalendarsByName("a calendar name")[0] for other calendars
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheet = doc.getActiveSheet(); // get the sctive sheet - could also use doc.getSheetByName("a sheet name");
var header = sheet.getRange(1,1,1,sheet.getLastColumn()).getValues()[0]; // assumes column heading are in first row
var usernameCol = false; // initialises usernameCol
for (i in header){
if (header[i]=="username"){ // loops through headings until it finds one called uesrname - this is the column where email addresses for the notifications are
usernameCol = parseInt(i)+1;
if (usernameCol){ // if we find the username column do more stuff
var data = sheet.getRange(2,usernameCol,sheet.getLastRow(),1).getValues(); // gets the column of emails as an array
var emaillist = data.join(", "); // comma seperates array to get a string of emails
var now = new Date().getTime(); // get time now as used in
// create a calendar event - title is used as message (could also be read or user input), set time +1 minute add guest list and send invites
cal.createEvent("please read your feedback on the Effect Feedback assignment",new Date(now+60000),new Date(now+60000), {guests:emaillist,sendInvites:true});
Browser.msgBox("Notification sent"); // let user know it's been completed
} else {
Browser.msgBox("Could not find column named 'username' with email addresses"); // let user something went wrong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment