Lesson 5: Text Message

While logging data is great for science experiments, most security application require somebody to be notified in the event a sensor registers an abnormal value. This can be done by adding another function to your Google spreadsheet. Add the following function below your doGet function:
 9 | function sendText() {
10 |   var recipient = '0123456789@txt.att.net';
11 |   var subject = 'Smart Home Alert';
12 |   var body = "Something's wrong!";
13 |   MailApp.sendEmail(recipient, subject, body);
14 | }

Code Breakdown
  • Line 10 should be your 10 digit phone number followed by the domain your carrier has set up for users to send text from email. Verizon customers would use something like 0123456789@vtext.com.
  • Line 11 is the subject. In the future you will customize it.
  • Line 12 is a simple message. In the future you will add sensor data.
  • Line 13 actually sends the email.
Authorize
Before you are able to send a text message, you will need to publish your app again. You will be prompted to authorize additional permissions, specifically the ability to send an email.

Send a Text Message
To test your function, choose your sendText function from the drop down menu.

Then click the run button. It will take a few seconds before you receive the text message.


Comments