DEV Community

MySMSGate
MySMSGate

Posted on • Originally published at mysmsgate.net

Send SMS from Google Sheets: Step-by-Step Guide with MySMSGate

Automating communications is key for any growing business, and the ability to send SMS from Google Sheets can unlock powerful workflows for marketing, notifications, and customer service. This comprehensive guide will walk you through the process, leveraging the power of Google Apps Script and MySMSGate's reliable and cost-effective SMS gateway to turn your spreadsheet into a powerful communication hub.

Whether you're sending appointment reminders, order updates, or personalized marketing messages, you'll discover how easy and affordable it is to automate SMS directly from your Google Sheets data, without needing complex infrastructure or expensive third-party services.

Step 1: Understand the Basics – Why Automate SMS from Google Sheets?

Google Sheets is more than just a spreadsheet; it's a versatile database for many small businesses and startups. Integrating SMS sending directly from your sheets offers numerous advantages:

  • Efficiency: Automate repetitive tasks like sending bulk notifications or personalized messages.
  • Data-Driven Communication: Use existing customer data in your sheets to trigger targeted SMS.
  • Cost-Effectiveness: Avoid manual sending, reduce errors, and choose an affordable SMS gateway like MySMSGate.
  • Accessibility: Manage your contacts and communications from a familiar and widely available platform.
  • Use Cases: Appointment reminders, delivery notifications, marketing campaigns, OTPs, internal alerts, customer support follow-ups, and more.

By connecting Google Sheets with an SMS gateway like MySMSGate, you transform your data into actionable communication, directly from your browser.

Step 2: Get Started with MySMSGate: Your Affordable SMS Gateway

Before we dive into coding, you'll need an SMS gateway that can handle your messages. MySMSGate offers a unique and highly cost-effective solution by turning your existing Android phones into powerful SMS sending devices. This approach bypasses expensive traditional SMS aggregators and removes the need for complex sender registrations like 10DLC.

  • Create Your Account: Head over to MySMSGate.net and sign up for a free account. The process is quick and doesn't require a credit card upfront.
  • Connect Your Android Phone: Once logged in, you'll find a QR code in your dashboard. Download the MySMSGate Android app from the Google Play Store on your chosen Android phone. Open the app and scan the QR code from your dashboard. Your phone will instantly connect, ready to send and receive messages. You can connect unlimited phones to one account, utilizing dual SIM support if needed.
  • Locate Your API Key: For Google Apps Script to communicate with MySMSGate, you'll need your unique API key. You can find this key in your MySMSGate dashboard under the 'API' section. Keep this secure, as it authenticates your requests.
  • Fund Your Account: MySMSGate operates on a pay-as-you-go model with no monthly fees or contracts. SMS messages cost just $0.03 per SMS, with packages available (e.g., 100 SMS for $3, 500 SMS for $12, 1000 SMS for $20). Add balance to your account to ensure seamless sending. Failed SMS are automatically refunded.

MySMSGate stands out as a top cheapest SMS API for small business, providing a robust REST API for developers and a user-friendly web dashboard for non-technical users.

Step 3: Prepare Your Google Sheet for SMS Sending

The structure of your Google Sheet is crucial. You'll need columns for the recipient's phone number and the message content. Consider adding more columns for personalization or tracking.

Let's set up a simple sheet with three columns:

  • Phone Number: The recipient's full international number (e.g., +12345678900).
  • Message: The text content of the SMS.
  • Status: A column to track whether the SMS was sent successfully (optional, but highly recommended for debugging and tracking).

Here’s an example of how your sheet might look:

Phone NumberMessageStatus+12345678900Hi John, your appointment is tomorrow at 2 PM.+19876543210Reminder: Your invoice is due on March 20th.+11122334455Special offer just for you! Use code SAVE10.Ensure your phone numbers are correctly formatted with the international dialing code (e.g., +1, +44, +91) as this is essential for reliable delivery.

Step 4: Access Google Apps Script

Google Apps Script is a JavaScript-based platform that lets you extend Google Workspace applications like Sheets, Docs, and Forms. It's where we'll write the code to connect your sheet to MySMSGate.

  • Open your Google Sheet.
  • Go to the menu bar and click on Extensions Apps Script.
  • A new browser tab will open, showing the Google Apps Script editor. You'll likely see a default file named Code.gs with an empty function, myFunction().

This is where we'll write our custom JavaScript code.

Step 5: Write the Google Apps Script Code

Now, let's write the JavaScript code that will read data from your Google Sheet and send it to the MySMSGate API. We'll create a function that iterates through rows, constructs the API request, and sends the message.

`function sendSmsFromSheet() {
  const SHEET_NAME = 'Sheet1'; // Replace with your sheet name
  const API_KEY = 'YOUR_MY_SMS_GATE_API_KEY'; // Replace with your MySMSGate API Key
  const API_ENDPOINT = 'https://mysmsgate.net/api/v1/send';

  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
  const dataRange = sheet.getDataRange();
  const values = dataRange.getValues();

  // Assuming headers are in the first row, start from the second row
  for (let i = 1; i < values.length; i++) {
    const row = values[i];
    const phoneNumber = row[0]; // Phone number from the first column
    const messageText = row[1]; // Message from the second column
    let statusCell = sheet.getRange(i + 1, 3); // Status in the third column (row index + 1, column index)

    // Skip if phone number or message is empty, or if status is already 'Sent'
    if (!phoneNumber || !messageText || statusCell.getValue() === 'Sent') {
      continue;
    }

    try {
      const payload = {
        'api_key': API_KEY,
        'number': phoneNumber,
        'message': messageText
        // 'device_id': 'YOUR_DEVICE_ID' // Optional: Specify a connected Android device ID
        // 'sim_slot': 1 // Optional: Specify SIM slot (1 or 2) if dual SIM
      };

      const options = {
        'method': 'post',
        'contentType': 'application/json',
        'payload': JSON.stringify(payload)
      };

      const response = UrlFetchApp.fetch(API_ENDPOINT, options);
      const responseData = JSON.parse(response.getContentText());

      if (responseData.success) {
        statusCell.setValue('Sent');
        Logger.log('SMS sent successfully to ' + phoneNumber);
      } else {
        statusCell.setValue('Failed: ' + responseData.message);
        Logger.log('Failed to send SMS to ' + phoneNumber + ': ' + responseData.message);
      }
    } catch (e) {
      statusCell.setValue('Error: ' + e.message);
      Logger.log('Error sending SMS to ' + phoneNumber + ': ' + e.message);
    }

    // Optional: Add a small delay to avoid hitting API rate limits if sending many messages
    // Utilities.sleep(1000); 
  }
}
`
Enter fullscreen mode Exit fullscreen mode

Explanation of the code:

  • SHEET_NAME: Make sure this matches the exact name of your Google Sheet tab (e.g., 'Sheet1', 'SMS List').
  • API_KEY: IMPORTANT: Replace 'YOUR_MY_SMS_GATE_API_KEY' with your actual API key from your MySMSGate dashboard.
  • API_ENDPOINT: This is the MySMSGate API endpoint for sending messages.
  • sheet.getDataRange().getValues(): This fetches all data from your active sheet.
  • Looping through rows: The for loop starts from i = 1 to skip the header row.
  • phoneNumber and messageText: These variables extract data from the first (index 0) and second (index 1) columns of each row. Adjust these indices if your columns are different.
  • statusCell: This gets a reference to the cell in the third column (index 2) of the current row, where we'll update the status.
  • payload: This JSON object contains the data required by the MySMSGate API: your api_key, the number, and the message. You can optionally include device_id and sim_slot if you have multiple devices or dual SIM phones connected and want to specify which one to use.
  • UrlFetchApp.fetch(): This is Google Apps Script's method for making HTTP requests. We're sending a POST request with JSON payload.
  • Response Handling: The script parses the API response and updates the 'Status' column accordingly, indicating 'Sent' or 'Failed' with an error message.

For more details on API parameters, refer to the MySMSGate API documentation.

Step 6: Configure and Test Your SMS Sender

After pasting the code into your Apps Script editor, you need to save it and grant the necessary permissions.

  • Save the Script: Click the floppy disk icon (Save project) or File Save.
  • Select Function: In the toolbar above the code editor, there's a dropdown menu (it might say 'myFunction' or 'sendSmsFromSheet'). Select sendSmsFromSheet.
  • Run the Script: Click the 'Run' icon (a triangle pointing right).
  • Authorize Permissions: The first time you run a script that accesses external services or your spreadsheet, Google will ask for your authorization. Follow these steps:
  • Click 'Review permissions'.
  • Select your Google account.
  • Review the permissions requested (e.g., 'See, edit, create, and delete all your Google Sheets spreadsheets', 'Connect to an external service').
  • Click 'Allow'.

  • Check Your Sheet: After successful authorization, the script will run. Go back to your Google Sheet. You should see the 'Status' column updated with 'Sent' for successfully delivered messages or 'Failed' with an error message.

  • Check Your Phone: Verify that your connected Android phone sent the messages.

If you encounter errors, check the 'Executions' tab in the Apps Script editor for logs and error details. Common issues include incorrect API key, malformed phone numbers, or an empty message.

Step 7: Automate SMS Sending with Triggers

Manually running the script is fine for testing, but the real power of Google Sheets SMS automation comes with triggers. You can set up your script to run automatically based on various events:

  • Time-driven: Run the script every hour, day, week, etc., to process new rows.
  • On form submit: If your sheet is populated by a Google Form, send an SMS immediately after a new form submission.
  • On edit: Trigger the script when a specific cell or range is edited.

Here's how to set up a time-driven trigger:

  • In the Apps Script editor, click the 'Triggers' icon (a clock) on the left sidebar.
  • Click '+ Add Trigger' in the bottom right corner.
  • Configure the trigger:

  • Choose which function to run: sendSmsFromSheet

  • Choose deployment to run: Head

  • Select event source: Time-driven

  • Select type of time-based trigger: E.g., Hour timer

  • Select hour interval: E.g., Every hour

  • Click 'Save'.

Now, your Google Sheet will automatically check for new messages to send at your specified interval, making your SMS campaigns truly hands-free. You can also integrate MySMSGate with tools like Zapier, Make.com, or n8n for more complex automation workflows, as detailed in our integration guides.

Step 8: Advanced Tips and Use Cases

Once you've mastered the basics of how to send SMS from Google Sheets, consider these advanced tips to maximize your automation:

  • Personalization: Add more columns to your sheet (e.g., Customer Name, Order Number) and dynamically insert them into your message text within the script.
  • Two-Way Communication: MySMSGate automatically forwards all incoming SMS to your web dashboard. You can then reply using the Web Conversations interface, giving you a chat-like experience directly from your browser.
  • Error Handling and Logging: Enhance your script to log more detailed success/failure messages, perhaps to a separate 'Logs' sheet, for better monitoring.
  • Cost Management: With MySMSGate's transparent pricing at $0.03/SMS, you can easily calculate costs. Compared to competitors like Twilio ($0.05-$0.08/SMS plus additional fees for phone numbers and 10DLC registration), MySMSGate offers significant savings, especially for small businesses or those sending high volumes.
  • Dedicated Devices/SIMs: If you have multiple Android phones connected to MySMSGate, you can specify which device_id or sim_slot to use for sending certain messages, enabling multi-branch management or distinct sender identities.
  • Schedule Messages: While Google Apps Script triggers can schedule, for more precise scheduling, you might manage message queues in your sheet and have the script send messages only when their scheduled time is met.

By leveraging these capabilities, your Google Sheet can become a powerful, integrated communication platform for your business.

Frequently Asked Questions

Can I send personalized SMS from Google Sheets?

Yes, absolutely! By adding columns for personalized data (like customer names, order numbers, or specific dates) in your Google Sheet, you can easily modify the Google Apps Script to dynamically insert this information into your SMS message. This allows for highly relevant and engaging communication with your recipients.

Is it expensive to send SMS from Google Sheets?

The cost depends on the SMS gateway you use. With MySMSGate, sending SMS from Google Sheets is highly affordable, costing just $0.03 per SMS with no monthly fees or contracts. This is significantly cheaper than many traditional SMS APIs like Twilio, which often charge $0.05-$0.08 per SMS plus additional fees for phone numbers and compliance. MySMSGate's model of using your own Android phones helps keep costs down.

Do I need coding skills to automate SMS from Google Sheets?

For the method outlined in this tutorial, basic familiarity with copying and pasting code and understanding simple variables in JavaScript (Google Apps Script) is helpful. You don't need to be an expert developer. The provided code snippet is ready to use with minor modifications (API key, sheet name). For non-technical users, MySMSGate also offers a web dashboard for sending SMS directly, or no-code integrations with Zapier, Make.com, and n8n, which can connect to Google Sheets without writing custom code.

How can I track SMS delivery status from Google Sheets?

In this tutorial, we've included a 'Status' column in your Google Sheet that updates with 'Sent' or 'Failed' directly after the MySMSGate API responds. For more detailed real-time delivery tracking, MySMSGate offers webhooks that can push delivery status updates back to your own systems, which a more advanced Google Apps Script could potentially process and update in your sheet or another database.

What are the alternatives to MySMSGate for Google Sheets SMS?

While MySMSGate offers a unique and cost-effective solution, other alternatives include traditional SMS APIs like Twilio, Vonage, or Plivo, which can also be integrated with Google Apps Script. However, these often come with higher per-message costs, monthly fees, and require compliance processes like 10DLC registration in the US. MySMSGate's use of your own Android phones eliminates these complexities and costs, making it a superior Twilio alternative for many small businesses and developers.

Top comments (0)