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

10,086

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.

Share:
10,086
Jean-Francois T.
Author by

Jean-Francois T.

Working in Software Testing for embedded application in Safety-Critical Embedded Systems. Passionate about Python and OCaml but also C language and other script language (Perl, TCL), and trying to learn Google Scripts/JS. Perpetual learner and love experiment new things. One true admirer of VS Code and Notepad++. Recently embarked on the Deep Learning adventure with startup "UnpackAI".

Updated on July 03, 2022

Comments

  • Jean-Francois T.
    Jean-Francois T. almost 2 years

    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);
    }
    
  • Jean-Francois T.
    Jean-Francois T. about 11 years
    Thank you Corey for your answer. However, living in China, I'm not sure my provider has such feature. I will inquire though.
  • Jean-Francois T.
    Jean-Francois T. about 10 years
    Indeed, my provider doesn't do it. And that makes us miss a lot of cool features
  • Jean-Francois T.
    Jean-Francois T. about 10 years
    IFTTT sounds promising. I will check on that
  • CodyBugstein
    CodyBugstein over 8 years
    But is there a way to send SMS from Google script
  • Greg Sadetsky
    Greg Sadetsky over 8 years
    @Imray I haven't tried it, but you might want to try connecting Google Script's URL Fetch Service (which allows outbound HTTP connections) with IFTTT's Maker Channel (which can be triggered using an HTTP connection). Let us know if it works!
  • CodyBugstein
    CodyBugstein over 8 years
    Cool idea! I think I will use Zapier webhooks though (I didn't think of it before you commented, but I'm already using Zapier and their webhooks are similar to IFTTT Maker)