I am working on SMS notification each time I receive an email that meets certain criteria; I decided to use Google App Scripts for this.
I have been inspired in particular by the following article https://developers.google.com/apps-script/articles/gmail_filter_sms. I also checked the related question in StackOverflow SMS Alerts for Important Mails in Gmail.
I improved the original script from developers.google.com by cleaning up the events the next time the script is run (I was receiving the SMS alerts each time the script is run). The script is currently working by using the label 'SendText' and creating events in calendar 'AlertSMS'.
However the SMS I receive only contain the subject and author of the email: I need to display the content of the email (or at least a part of it). I tried with no luck to add it to the description of the event. Anybody got an idea on how to do it?
Hereunder, the code of my script:
function sendText() {
var now = new Date().getTime();
// Delete old events
var events = CalendarApp.openByName('AlertSMS').getEvents(new Date('January 1, 2010 EST'), new Date(now-30000));
for (i in events) {
events[i].deleteEvent();
}
// Get list of emails to set alert for
var label = GmailApp.getUserLabelByName('SendText');
var threads = label.getThreads();
// Create new events for emails alert
for(i in threads){
var message=threads[i].getMessages()[0];
CalendarApp.openByName('AlertSMS').createEvent('[SMS] '+threads[i].getFirstMessageSubject()+' -from- '+message.getFrom(),
new Date(now+60000), new Date(now+60000), { description:message.getBody() }).addSmsReminder(0);
}
label.removeFromThreads(threads);
}