Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMS notification for Gmail using Google Apps Scripts: how to display content of the email?

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);
}
like image 418
Jean-Francois T. Avatar asked Feb 13 '13 07:02

Jean-Francois T.


People also ask

How do you add HTML content to an email sent via App Script?

You can send email using MailApp. sendEmail() function like this: MailApp. sendEmail({ to: email, subject: "This is a test email", htmlBody: message });

Does Gmail have email scripting?

If you know JavaScript, you can use Google Apps Script to add features to many Google products including Gmail. If you've used Office scripting, the idea is the same, although obviously the implementation is very different.

Does Gmail have push notifications?

Whenever you get a new email sent to your Gmail, you can now get a push notification sent to your mobile device. You will need to install the Power Automate app for iOS or Android to use this flow.


1 Answers

You can use services such as (the completely free) IFTTT or (the somewhat free) Zapier to trigger an SMS action upon receiving emails matching a criteria.

Here are some IFTTT "recipes" which connect GMail to SMS.

like image 113
Greg Sadetsky Avatar answered Oct 06 '22 01:10

Greg Sadetsky