-
-
Save utkarshkukreti/1fe9b3784beb368d8406 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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