Skip to content

Instantly share code, notes, and snippets.

/smsMail

Created Jan 31, 2014
Embed
What would you like to do?
function smsMail()
{
try
{
var label = GmailApp.getUserLabelByName('smsMail');
var threads = label.getThreads();
var now = new Date().getTime();
var cal=getCalendar();
for(i in threads)
{
cal.createEvent(threads[i].getFirstMessageSubject()+": "+threads[i].getMessages()[0].getFrom(),new Date(now+60000),
new Date(now+60000)).removeAllReminders().addSmsReminder(0);
}
label.removeFromThreads(threads);
}
catch(err)
{
Logger.log("Error Occured"+ err.toString());
}
}
function getCalendar()
{
try
{
var cal=CalendarApp.getOwnedCalendarsByName("smsMail")[0];
if (!cal)
{
cal=CalendarApp.createCalendar("smsMail");
return cal;
}
else
{
return cal;
}
}
catch(e)
{
Logger.log("Error Occured"+ e.toString());
}
}
function onOpen()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "Authorize", functionName: "authorize"},
{name: "Stop SMS alerts", functionName: "stopsmsalerts"}
];
ss.addMenu("Gmail SMS Alerts", menuEntries);
}
function authorize(){}
function stopsmsalerts()
{
var allTriggers = ScriptApp.getScriptTriggers();
for(var i=0; i < allTriggers.length; i++)
ScriptApp.deleteTrigger(allTriggers[i]);
Browser.msgBox("Success", "You will not be getting SMS alerts anymore.",Browser.Buttons.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment