
Notification of new emails in Gmail via SMS using Google Calendar + Google Apps Script
- Tutorial
Alas, this method will stop working since June 27th, 2015, because Google disables the SMS alerts feature for the calendar.
support.google.com/calendar/answer/45351?hl=en

I want to share with my Harbra community a useful, from my point of view, live hack: SMS notifications about new mail in the Gmail box. This is implemented by a small script that lives and works in Google Drive (formerly Google Docs).
The principle of operation is as follows: the timer script checks the Inbox folder in the mailbox and if it detects new messages, it creates an event in google calendar with the name as the subject of the message and includes an SMS notification for it. As a result, you receive an SMS message of the following content:
Implementation details, as always, under the “cut”.
So, what you need to start: you must have a phone number attached to Google Calendar, how to do it is written here - Mobile phone registration:
support.google.com/calendar/bin/answer.py?hl=en&hlrm=en&answer=45351
The next few steps must be completed so that the script can correctly process new mail.
Step 1 : Create a new shortcut in Gmail with a name, for example, SMSnotify (or any other, at your discretion). How to do it is written here - Using shortcuts:
support.google.com/mail/bin/answer.py?hl=en&hlrm=en&answer=118708#0
Step 2 : Create a filter that will apply the SMSnotify shortcut to all incoming messages (To:
support.google.com/mail/bin/answer.py?hl=en&hlrm=en&answer=6579#0
Thus, all new messages will be marked with this label.
Step 3: Log in to Google Drive (or Docs, if you haven’t switched yet) and create a new Spreadsheet. Open the created table and select Tools> Script Editor in the top menu.

Step 4 : Due to the fact that when you install the notification directly from the code, it is often possible types of errors
(see more here: code.google.com/p/google-apps-script-issues/issues/detail?id=264 )
It is necessary to create a add. calendar and configure SMS notifications: set the default for all new appointments like this:
Settings-> Calendars-> Notifications-> Default-> SMS -> %% min
In this example, the calendar name will be " email "
I was pleasantly surprised to learn that now from the guglodisk interface you can create scripts as separate applications that are not built into the table. So, “ Step 3 ” can now be reduced to the following:

A new page with the Google “script-IDE” will open, and here the fun begins.
The full text of the code is under the spoiler
After you entered the code, you need to create a trigger by which the script will be launched. To do this, click on the " Resources " menu , and in it on " Triggers the current script ."

We need a time-driven trigger with a repetition rate of, for example, one hour.

In the process of changing the trigger conditions or saving changes in the script itself, an authorization window will appear. Feel free to authorize :)

After all the manipulations, as a test, we try to run the script to execute.

Sometimes you may receive messages about unsuccessful script execution (even if the code is correct and before that everything worked). These messages can be disabled (although I left): you need to click on “notifications” in the trigger editor window and this window will appear

Thank you for reading to the end, I hope I haven’t forgotten anything. I would be very happy if someone comes in handy.
Any comments, additions, criticisms are welcome! Recently discovered this wonderful API and just started to get acquainted with it.
Related links:
Standard Services Documentation (English only) - developers.google.com/apps-script/defaultservices
Various Guides (English only) - developers.google.com/apps-script/articles
Acknowledgments: Thanks to users of Yan169 and OlegT for their interest and advice!
support.google.com/calendar/answer/45351?hl=en
Important! SMS alerts will be disabled on June 27.
Starting June 27, 2015, you will no longer receive SMS alerts from Google Calendar. The SMS alert feature was introduced before the widespread adoption of smartphones. However, modern mobile devices allow you to receive alerts in a more convenient format, and even offline.
To view alerts, you can use the calendar application, which was installed on your smartphone by default, or download Google Calendar for Android or iPhone. Learn more about alerts.
Note: This change will not affect Google Apps for Work, Education, and Government users.

I want to share with my Harbra community a useful, from my point of view, live hack: SMS notifications about new mail in the Gmail box. This is implemented by a small script that lives and works in Google Drive (formerly Google Docs).
The principle of operation is as follows: the timer script checks the Inbox folder in the mailbox and if it detects new messages, it creates an event in google calendar with the name as the subject of the message and includes an SMS notification for it. As a result, you receive an SMS message of the following content:
Напоминание: Тема письма @ дата и время
Implementation details, as always, under the “cut”.
So, what you need to start: you must have a phone number attached to Google Calendar, how to do it is written here - Mobile phone registration:
support.google.com/calendar/bin/answer.py?hl=en&hlrm=en&answer=45351
The next few steps must be completed so that the script can correctly process new mail.
Step 1 : Create a new shortcut in Gmail with a name, for example, SMSnotify (or any other, at your discretion). How to do it is written here - Using shortcuts:
support.google.com/mail/bin/answer.py?hl=en&hlrm=en&answer=118708#0
Step 2 : Create a filter that will apply the SMSnotify shortcut to all incoming messages (To:
<ваше-имя> @ gmail.com
) How to do this is written here - Using filters: support.google.com/mail/bin/answer.py?hl=en&hlrm=en&answer=6579#0
Thus, all new messages will be marked with this label.
Step 3: Log in to Google Drive (or Docs, if you haven’t switched yet) and create a new Spreadsheet. Open the created table and select Tools> Script Editor in the top menu.

Step 4 : Due to the fact that when you install the notification directly from the code, it is often possible types of errors
Calendar: Mismatch: etags
(see more here: code.google.com/p/google-apps-script-issues/issues/detail?id=264 )
It is necessary to create a add. calendar and configure SMS notifications: set the default for all new appointments like this:
Settings-> Calendars-> Notifications-> Default-> SMS -> %% min
In this example, the calendar name will be " email "
I was pleasantly surprised to learn that now from the guglodisk interface you can create scripts as separate applications that are not built into the table. So, “ Step 3 ” can now be reduced to the following:

A new page with the Google “script-IDE” will open, and here the fun begins.
The full text of the code is under the spoiler
Click this caption to show / hide the code.
function my_notification()
{
var calendar = CalendarApp.getOwnedCalendarsByName('email')[0]; //открываем календарь с именем "email"
var threads = GmailApp.getUserLabelByName('SMSnotify').getThreads(); //переменная, в которой хранится коллекция цепочек с ярлыком SMSnotify
var now = new Date();
if(threads == 0) return; // прекращение выполнения, если новых цепочек нет
for(i in threads) // создаем события
{
calendar.createEvent(threads[i].getFirstMessageSubject(),
new Date(now.getTime()+60000),
new Date(now.getTime()+60000));
}
GmailApp.getUserLabelByName('SMSnotify').removeFromThreads(threads); //снимаем метки "SMSnotify" с цепочек
}
After you entered the code, you need to create a trigger by which the script will be launched. To do this, click on the " Resources " menu , and in it on " Triggers the current script ."

We need a time-driven trigger with a repetition rate of, for example, one hour.

In the process of changing the trigger conditions or saving changes in the script itself, an authorization window will appear. Feel free to authorize :)

After all the manipulations, as a test, we try to run the script to execute.

Sometimes you may receive messages about unsuccessful script execution (even if the code is correct and before that everything worked). These messages can be disabled (although I left): you need to click on “notifications” in the trigger editor window and this window will appear

Thank you for reading to the end, I hope I haven’t forgotten anything. I would be very happy if someone comes in handy.
Any comments, additions, criticisms are welcome! Recently discovered this wonderful API and just started to get acquainted with it.
Related links:
Standard Services Documentation (English only) - developers.google.com/apps-script/defaultservices
Various Guides (English only) - developers.google.com/apps-script/articles
Acknowledgments: Thanks to users of Yan169 and OlegT for their interest and advice!