Send SMS Notifications from Google Sheets Using Twilio and Apps Script

Sometimes an email isn't enough — you need to send an SMS. Twilio's API makes this easy, and Apps Script's UrlFetchApp can call it directly from your spreadsheet.

Prerequisites

  1. Sign up at twilio.com and get a trial account.
  2. From the Twilio Console, note your Account SID, Auth Token, and Twilio phone number.
  3. Store these in Apps Script's PropertiesService (never hardcode credentials).
function storeTwilioCredentials() { const props = PropertiesService.getScriptProperties(); props.setProperties({ 'TWILIO_ACCOUNT_SID': 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'TWILIO_AUTH_TOKEN': 'your_auth_token', 'TWILIO_FROM_NUMBER': '+15551234567', }); }

Send a single SMS

function sendSms(toNumber, message) { const props = PropertiesService.getScriptProperties(); const accountSid = props.getProperty('TWILIO_ACCOUNT_SID'); const authToken = props.getProperty('TWILIO_AUTH_TOKEN'); const fromNumber = props.getProperty('TWILIO_FROM_NUMBER'); const url = `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Messages.json`; const options = { method: 'POST', headers: { Authorization: 'Basic ' + Utilities.base64Encode(`${accountSid}:${authToken}`), }, payload: { To: toNumber, From: fromNumber, Body: message, }, muteHttpExceptions: true, }; const response = UrlFetchApp.fetch(url, options); const result = JSON.parse(response.getContentText()); if (result.sid) { Logger.log(`SMS sent. SID: ${result.sid}`); } else { Logger.log(`Error: ${result.message}`); } }

Send SMS to all numbers in a Sheet

Set up a sheet with columns: Name (A), Phone (B), Message (C), Sent? (D).

function sendBulkSms() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const data = sheet.getDataRange().getValues().slice(1); // Skip header data.forEach((row, i) => { const [name, phone, message, sent] = row; if (sent === 'Yes' || !phone || !message) return; sendSms(phone, message.replace('{{name}}', name)); // Mark as sent sheet.getRange(i + 2, 4).setValue('Yes'); Utilities.sleep(500); // Respect Twilio rate limits }); Logger.log('Bulk SMS complete.'); }

Send an alert when a value crosses a threshold

function checkAndSmsAlert() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const stockLevel = sheet.getRange('B2').getValue(); const threshold = 50; if (stockLevel < threshold) { sendSms( '+15559876543', `⚠️ Low stock alert! Current level: ${stockLevel} units (threshold: ${threshold}).` ); } }

Schedule a daily SMS reminder

function scheduleDailySms() { ScriptApp.newTrigger('sendDailyReminder') .timeBased() .everyDays(1) .atHour(9) .create(); } function sendDailyReminder() { sendSms('+15551234567', 'Good morning! Don\'t forget to review your daily report in Google Sheets.'); }

Tips

  • Twilio trial accounts can only send SMS to verified numbers. Upgrade to a paid account for unrestricted sending.
  • Phone numbers must be in E.164 format: +15551234567 (country code + number, no spaces or dashes).
  • Twilio charges per SMS — keep an eye on your usage in the Twilio Console.
  • For two-way SMS (receiving replies), look into Twilio's webhook configuration and Apps Script Web Apps.
  • The Twilio free tier gives you a small credit to test with — plenty to build and verify your integration.