A command line interface can sometimes be useful for quick sending of an SMS message from another application.
A message thread on our discussion board provided a simple example that has been referenced frequently. The purpose of this document is to provide an updated script which offers more flexibility. This updated script allows recipient phone numbers, and the message text, to be specified on the command line.
Assuming that the script is saved as a file named sms.js, you would issue the following command:
cscript sms.js PhoneNumber1[,PhoneNumber2,...] SMS Message Text
(cscript.exe is the Windows Script Host, which is a component of Windows which should be located in the \Windows\System32 directory.)
Examples:
cscript sms.js +44777777777 This is a test message
cscript sms.js +44777777777,+44777777778 This is a test message to 2 recipients
The SMS.JS script file is displayed below. Save everything between the “—begin sms.js—” and “—end sms.js—” markers to a file named SMS.JS. Edit the NowSMSServerAddress, NowSMSUserName and NowSMSPassword variable settings as appropriate for your installation. This script is also available at the following link: http://www.nowsms.com/download/sms.js.txt
—begin sms.js—
/*
This is a command line script for sending an SMS message via NowSMS.
Below, you must substitute in the address of your NowSMS server, plus a valid username and password for
an account defined in the “SMS Users” list of that server.
Note: This script uses the encodeURIComponent method introduced in Internet Explorer 5.5. If you are running
Windows 2000 or an earlier version of Windows, you must have Internet Explorer 5.5 or later installed for this
script to work.
*/
var NowSMSServerAddress = “http://127.0.0.1:8800″;
var NowSMSUserName = “test”;
var NowSMSPassword = “test”;
function HTTPGET(strURL)
{
var strResult;
try
{
// Create the WinHTTPRequest ActiveX Object.
var WinHttpReq = new ActiveXObject(“Msxml2.XMLHTTP” /* or “WinHttp.WinHttpRequest.5″*/);
// Create an HTTP request.
var temp = WinHttpReq.Open(“GET”, strURL, false);
// Send the HTTP request.
WinHttpReq.Send();
// Retrieve the response text.
strResult = WinHttpReq.ResponseText;
}
catch (objError)
{
strResult = objError + “\n”
strResult += “WinHTTP returned error: ” +
(objError.number & 0xFFFF).toString() + “\n\n”;
strResult += objError.description;
}
// Return the response text.
return strResult;
}
var strRequest;
if (WScript.Arguments.Count() < 2) {
WScript.Echo (“Usage: ” + WScript.ScriptName + ” PhoneNumber1[,PhoneNumber2,...] Message Text\r\n”);
WScript.Quit();
}
strRequest = NowSMSServerAddress + “/?PhoneNumber=” + encodeURIComponent(WScript.Arguments(0)) + “&User=” + encodeURIComponent(NowSMSUserName) + “&password=” + encodeURIComponent(NowSMSPassword) + “&text=”;
for (i=1; i<WScript.Arguments.Count(); i++)
{
if (i > 1) {
strRequest += “%20″;
}
strRequest += encodeURIComponent(WScript.Arguments(i));
}
WScript.Echo(HTTPGET(strRequest));
—end sms.js—
Related pages:
- Send SMS from a Command Line Interface A command line interface can sometimes be useful for quick sending of an SMS message from another application. A message...
- Sending WAP Push and Binary SMS from the Command Line In past postings, we’ve provided a variety of command line script examples that make it easy to interface with NowSMS...
- Send MMS Message from Command Line A Windows command line script that enables sending MMS messages from the command line can be downloaded form http://www.nowsms.com/download/sendmms.vbs.txt. Assuming...
- Send MMS from the Command Line Last time, I posted a Windows JScript file that could be used to enable the sending of OMA Client Provisioning...
- Send OMA Client Provisioning (OTA XML Settings) from the Command Line Three years ago on our discussion board we posted a simple Windows JScript that could be used to send an...
- Send SMS from PHP Script (Updated) Quite a few people use the PHP script that Bryce provided 7-1/2 years ago for sending an SMS message through...
- 2-way SMS Command Speed and Performance (updated) Before I get to the speed/performance issue that I want to highlight, I’ll review some of the basics of 2-way...
- 2-Way SMS Returning a Non-Text Response It is a relatively simple process to define a 2-way command that returns a text response to the message sender....
- Send SMS from PHP Script Over the coming weeks, I’m planning to collect various PHP, ASP and other script examples to provide some examples of...
- 2-way SMS: Multiple operators with the same shortcode This configuration issue comes up quite a bit. Let’s say that you are connecting directly to multiple mobile operators, and...
Topic Category: command line interface
For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...

Click here to download a free trial version of NowSMS & MMS Gateway, NowSMS Lite or NowWAP Gateway.
Learn more about NowSMS Lite.