This Google Script page says that stackoverflow is the place to post Google Script questions, so here I am.
I want to use a Google Script to automatically send text mess
It depends on the cell phone carrier. To send a text to a Sprint number, for example, put the message in an email addressed in this manner:
2013456789@messaging.sprintpcs.com
(yes, they still have the "pcs" in the domain name...)
I was recently part of a team that produced a Google add-on named Text gBlaster that accomplishes what I believe you are asking for. It makes like easy so feel free to give it a try.
Aside from that, if you want to do it yourself without it sending via the carrier's email service (that Bill mentions above, which is a fine solution) then you will need to use a third party like Twilio (which is who we are using). You basically use the spreadsheet to send the request to Twilio and then Twilio sends the messages out.
Here is some basic code you can use with Twilio if you go that route. You will need to define toNumber, bodyMessage, SID, Token, and twilioNumber. toNumber is the number that is receiving the message, bodyMessage is the body of the text message, SID & Token are provided to you when you create a Twilio account, and twilioNumber is the phone number that you have through Twilio that the message will be sent from.
function sendSms(toNumber,bodyMessage, SID, Token, twilioNumber) {
var url = "https://api.twilio.com/2010-04-01/Accounts/" + // URL used to enter correct Twilio acct
SID + "/SMS/Messages.json";
var options = { // Specify type of message
method: "post", // Post rather than Get since we are sending
headers: {
Authorization: "Basic " +
Utilities.base64Encode(SID + ":" + Token)
},
payload: { // SMS details
From: twilioNumber,
To: toNumber,
Body: bodyMessage
}
};
var response = UrlFetchApp.fetch(url, options); // Invokes the action
Logger.log(response);
}