ActiveXperts SMS Component

Quicklinks

HTML sample - Send SMS text through a COM/USB GSM modem

The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.


Introduction

In this example we are going to create an HTML web form to send SMS messages. This demo project will ask the user to give a phone number and a message body in the web form. A GSM modem is required for this demo.

Step 1: Installation of the ActiveXperts SMS Component

When using HTML, there are two ways to install the ActiveXperts SMS Component on a client PC:

  • Automatically using HTML code;
  • Using the ActiveXperts SMS Component InstallShield installation.

Automatic installation using HTML code

You can install the ActiveXperts SMS Component automatically using the following HTML code on top of the HTML page:

<object codebase="http://www.activexperts.com/files/sms-component/cab/6.0/AxSms.cab"
        classid="CLSID:1AECF5F6-A43F-41B4-9E75-24D11017AFA9" ></object>

The ActiveXperts SMS Component will be installated automatically. The user will be asked to confirm the installation, because the DLL is coming from an untrusted site (www.activexperts.com). There are two ways to avoid prompting:

  • Add the ActiveX/COM location to the user's trusted sites. You can manage trusted manually (by using the Internet Explorer), through a logon script (by appyling the registry change from the logon script) or by using Active Directory Group Policies;
  • Or use a trusted location for the DLL. For instance your Intranet site, because most probably this site has already been added to the list of trusted sites for all users.

Manual installation using the ActiveXperts SMS Component installation procedure

On each client PC, download the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create the SMS objects in HTML

You must use Javascript to declare and create the objects.

Use the following Javascript code to declare and create the GSM object:

var objGsm          = new ActiveXObject("AxSms.Gsm");
var objSmsMessage   = new ActiveXObject("AxSms.Message");
var objSmsConstants = new ActiveXObject("AxSms.Constants");

Step 3: Gather information

The following code will get the recipient telephone number and the content of the text message from the HTML form. This data will be stored in the 'objSmsMessage' object. The last line of this code specifies that the message is beeing sent as plain text.

//Message Settings
objSmsMessage.Clear();
objSmsMessage.ToAddress = objForm.txtToAddress.value;
objSmsMessage.Body = objForm.txtBody.value;
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;

Step 4: Send the SMS message

The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects. The timeout value is set to 10 seconds, which means that the modem will try to send the message for 10 seconds, after this value it will stop trying.

//Send the message !
objGsm.SendSms(objSmsMessage, iMultipart, 10000);

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveXperts SMS Component package.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>ActiveXperts SMS Component Javascript Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/SampleStylesheet.css" />
    
  <script language="JavaScript" type="text/javascript">
    var objGsm = new ActiveXObject("AxSms.Gsm");

    window.attachEvent("onload", PageLoaded, false);

    function PageLoaded() {
      document.getElementById("APIinfo").innerHTML = "Build: " + objGsm.Build + "; 
        Module: " + objGsm.Module;

      var objForm = document.forms["GsmSampleForm"];
      var strDevice = objGsm.FindFirstDevice();

      objForm.txtResult.value = "n/a";        

      while (objGsm.LastError == 0) {
        var NewOption = document.createElement('option');
        NewOption.text = NewOption.value = strDevice;

        objForm.ddlDevices.add(NewOption);
        strDevice = objGsm.FindNextDevice();
      }

      for (var i = 1; i <= 20; i++) {
        var NewOption = document.createElement('option');
        NewOption.text = NewOption.value = "COM" + i; ;

        objForm.ddlDevices.add(NewOption);
      }
    }

    function SendMessage() {
      var objSmsMessage = new ActiveXObject("AxSms.Message");
      var objSmsConstants = new ActiveXObject("AxSms.Constants");

      var iFlowControl = objSmsConstants.GSM_FLOWCONTROL_AUTO;

      var objForm = document.forms["GsmSampleForm"];

      var strName = objForm.ddlDevices.value;
      var strPincode = objForm.txtPincode.value;
      var iDeviceSpeed = objForm.ddlDeviceSpeed.value;

      objGsm.Clear();
      objGsm.Open(strName, strPincode, iFlowControl, iDeviceSpeed);

      if (objGsm.LastError != 0) {
          UpdateResult(objForm);
      }
      else {
        //Message Settings
        objSmsMessage.Clear();
        objSmsMessage.ToAddress = objForm.txtToAddress.value;
        objSmsMessage.Body = objForm.txtBody.value;
        objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;

        var iMultipart = (objForm.cbxMultipart.checked == 1) 
          ? objSmsConstants.MULTIPART_OK
          : objSmsConstants.MULTIPART_TRUNCATE;

        if (objForm.cbxFlash.checked == 1)
          objSmsMessage.DataCoding = objSmsConstants.GSM_DATACODING_FLASH;

        //Send the message !              
        objGsm.SendSms(objSmsMessage, iMultipart, 10000);
        UpdateResult(objForm);
      }
    }

    function UpdateResult(objForm) {
      objForm.txtResult.value = objGsm.LastError + ": " + 
        objGsm.GetErrorDescription(objGsm.LastError);
      objGsm.Close();
    }
  </script>
  <body>
    <div class="ax_maincontainer">
        
      <div class="ax_container">
        <h1>SMS Component Javascript GSM Sample</h1>
        <hr />
        <p>
        This demo requires a GSM modem or GSM phone connected to your computer. 
        A SIM card is required in this GSM modem. 
        The product works with almost all available GSM modems. 
        </p>
        <form name="GsmSampleForm" action="gsm.html" method="post">
          <h2>SMS Component:</h2>
          <h3 id="APIinfo"></h3>
    
          <!-- Device -->
          <label for="Devices">Device:</label>
          <p>
            <select id="Devices" name="ddlDevices"></select>
          </p>
                
          <!-- Device Speed -->
          <label for="DeviceSpeed">Device Speed:</label>
          <p>
            <select id="DeviceSpeed" name="ddlDeviceSpeed">
              <option value="0">Default</option>

              <option value="110">110</option>
              <option value="300">300</option>
              <option value="600">600</option>
              <option value="1200">1200</option>
              <option value="2400">2400</option>
              <option value="4800">4800</option>

              <option value="9600">9600</option>
              <option value="14400">14400</option>
              <option value="19200">19200</option>
              <option value="38400">38400</option>
              <option value="56000">56000</option>
              <option value="57600">57600</option>

              <option value="64000">64000</option>
              <option value="115200">115200</option>
              <option value="128000">128000</option>
              <option value="230400">230400</option>
              <option value="256000">256000</option>
              <option value="460800">460800</option>

              <option value="921600">921600</option>
            </select>
            (only applies to direct ports, i.e. COM1, COM2, etc.)
          </p>
        
          <!-- Pincode -->
          <label for="Pincode">Pincode:</label>
          <p>
            <input type="password" id="Pincode" name="txtPincode" />
            (only required if SIM card has PIN code)
          </p>
   
          <!-- ToAddress -->
          <label for="ToAddress">ToAddress:</label>
          <p>
            <input type="text" id="ToAddress" name="txtToAddress" value="[ToAddress]" />
            <a href="http://www.activexperts.com/support/sms-component/?kb=Q4200015" 
                target="_blank">Recipient number format</a>
          </p>
                
          <!-- Body, Multipart, Flash -->
          <label for="Body">Body:</label>
          <p>
            <textarea id="Body" name="txtBody" style="height:55px;">
                Hello world send from ActiveXperts SMS Component!
            </textarea><br />
    
            <input type="checkbox"class="ax_cbFix" id="Multipart" name="cbxMultipart" value="1" />
            <label for="Multipart">Allow Multipart</label><br />
            
            <input type="checkbox"class="ax_cbFix" id="Flash" name="cbxFlash" value="1" />
            <label for="Flash">Flash</label>
          </p>

          <!-- Send button -->
          <div class="ax_clearLabel"></div>
          <p>
            <input type="button" onclick="SendMessage()" value="Send SMS Message!" />
          </p>

          <!-- Result -->
          <label><b>Result:</b></label>
          <p>
            <input type="text" name="txtResult"class="ax_FullWidth" 
                style="font-weight: bold;" value="n/a" />
          </p>                
        </form>
            
      </div><!-- /container -->
    </div><!-- /maincontainer -->
  </body>
</html>  

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-component. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.