ActiveXperts SMS Component

Quicklinks

HTML sample - Send SMS text through an SMPP provider

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 interface to send SMS messages. This demo project will ask the user to give a phone number and a message body in the web interface.

A subscription to an SMPP provider is required. For this demo you can send a limited number of messages through our own gateway.

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.

The following code will show you how to declare and create the SMPP and SMS objects. We will use the 'objSmpp' object to send the message itself. The 'objSmsMessage' object will be used to store information of the message and the 'objSmsConstants' object containes constant values releated to the SMS objects.

var objSmpp = new ActiveXObject("AxSms.Smpp");
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.

objSmsMessage.ToAddress = objForm.txtToAddress.value;
objSmsMessage.Body = objForm.txtMessage.value;
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;

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

Step 4: Send SMS messages

The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects.

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

objSmpp.SubmitSms(objSmsMessage, iMultipart);

Appendix: Full source code

The following HTML code shows how to send a SMS using a connected GSM modem:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>ActiveXperts SMS Component Javascript Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
  
<object 
  codebase="http://www.activexperts.com/files/sms-component/cab/6.0/AxSms.cab" 
  classid="CLSID:1AECF5F6-A43F-41B4-9E75-24D11017AFA9" ></object>
  <script language="JavaScript" type="text/javascript">
    var objSmpp = new ActiveXObject("AxSms.Smpp");
    
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    objSmpp.LogFile = fso.GetSpecialFolder(2) + "\\ActiveXperts.Smpp.log";
    // Windows default: 'C:\Users\%USERNAME%\AppData\Local\Temp\ActiveXperts.Smpp.log'
    
    window.attachEvent("onload", PageLoaded, false);
    
    var Credentials = new (function() {
      // NOTE: during installation of the ActiveXperts SMS Component, a unique login and password 
      // is created for you. This login and password can be used to send a few SMS messages 
      // through the smpp.activexperts-labs.com gateway, for free
      // The 'GetSmsDemoAccountInfo' reads the unique account info from a file that was created 
      // during installation
    
      var objShell = new ActiveXObject("WScript.Shell");
      var strDirectory = objShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveXperts
          \\SMS Component\\InstallRoot");
      strDirectory += "\\Utilities\\activexperts-labs.txt";
      
      var objFileSystem = new ActiveXObject("Scripting.FileSystemObject");
      var objFile = objFileSystem.OpenTextFile(strDirectory, 1, false, 0);
      
      objFile.ReadLine();            //1st line is a comment line; skip it
      this.strAccount = objFile.ReadLine();  //2nd line is the account
      this.strPassword = objFile.ReadLine();  //3rd line is the password
    })(); 
    
    
    function PageLoaded() {
      document.getElementById("APIinfo").innerHTML = "Build: " + objSmpp.Build + "; " + 
                                                     "Module: " + objSmpp.Module;
      
      var objForm = document.forms["SmppSampleForm"];
      objForm.Logfile.value = fso.GetSpecialFolder(2) + "\\ActiveXperts.Smpp.log";
      objForm.txtSystemID.value = Credentials.strAccount;
      objForm.txtPassword.value = Credentials.strPassword;
      objForm.txtResult.value = "n/a";
    }
    
    function SendMessage() {
      var objForm = document.forms["SmppSampleForm"];
      
      objSmpp.Connect(objForm.txtServer.value, objForm.txtServerPort.value, 5000);
      
      if (objSmpp.LastError != 0) {
        UpdateResult(objForm);
      }
      else {
        var objSmsConstants = new ActiveXObject("AxSms.Constants");
        
        var iSystemMode = objSmsConstants.SMPP_BIND_TRANSCEIVER;
        var iVersion = objSmsConstants.SMPP_VERSION_34;
        
        objSmpp.Bind(iSystemMode, 
                     objForm.txtSystemID.value, 
                     objForm.txtPassword.value, 
                     objForm.txtSystemType.value, iVersion, 0, 0, "", 5000);
        
        if (objSmpp.LastError != 0) {
          UpdateResult(objForm);
        }
        else {
          var objSmsMessage = new ActiveXObject("AxSms.Message");
          
          objSmsMessage.Clear();
          objSmsMessage.RequestDeliveryReport = true;
          objSmsMessage.ToAddress = objForm.txtToAddress.value;
          objSmsMessage.Body = objForm.txtMessage.value;
          objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;
          
          if (objForm.cbxFlash.checked == 1)
           objSmsMessage.DataCoding = objSmsMessage.DataCoding | objSmsConstants.DATACODING_FLASH;
          
          var iMultipart = (objForm.cbxMultipart.checked == 1) ?
            objSmsConstants.MULTIPART_OK : objSmsConstants.MULTIPART_TRUNCATE;
          
          objSmpp.SubmitSms(objSmsMessage, iMultipart);
          
          if (objSmpp.LastError != 0) {
            UpdateResult(objForm);
          }
          else {
            while (objSmpp.WaitForSmsUpdate(1000)) {
              objSmsMessage = objSmpp.FetchSmsUpdate();
              
              if (objSmpp.LastError == 0) {
                break;
              }
              objSmpp.Sleep(100);
            }
            
            var strMessageReference = objSmsMessage.Reference;
            var bSearchDeliveryReport = true;
            
            while (bSearchDeliveryReport) {
              var objMessage = objSmpp.ReceiveMessage();
              
              while (objSmpp.LastError == 0) {
                if (objMessage.SmppIsDeliveryReport) {
if (strMessageReference == objMessage.Body.substr((objMessage.Body.indexOf("id:")+3),8))
                  {
                    objForm.txtMessageStatus.value = 
                        objMessage.Body.substr(objMessage.Body.indexOf("stat:") + 5, 7);
                    bSearchDeliveryReport = false;
                    break;
                  }
                }
                objMessage = objSmpp.ReceiveMessage();
              }
              objSmpp.Sleep(1000);
            }
            UpdateResult(objForm);
          }
        }
      }
    }
    
    function UpdateResult(objForm) {
      objForm.txtResult.value = objSmpp.LastError;
    }
  </script>
</head>
<body>
  <div class="ax_maincontainer">
    <div class="ax_header">
      <div class="ax_stroke"></div>
      <div class="ax_logo"></div>
    </div><!-- /header -->
    <div class="ax_menu">
      | <a href="index.html">Home</a> 
      | <a href="gsm.html">GSM</a>
      | <a href="pagersnpp.html">Pager SNPP</a>
      | <a href="smpp.html">SMPP</a>
      | <a href="ussd.html">USSD Commands</a>
      | <a href="smtp.html">SMTP</a>
      | <a href="pop3.html">POP3</a> |
    </div><!-- /menu -->
    <div class="ax_container">
      <h1>SMS Component Javascript SMPP Sample</h1>
      <hr />
      <p>
      This demo allows you to send SMS messages over SMPP. If you don't have an SMPP subscription,
      you can use the ActiveXperts SMPP Demo Gateway. You can send out a few SMS messages
      for free through this gateway.
      </p>
      <form name="SmppSampleForm" action="smpp.html" method="post">
        <h2>SMS Component:</h2>
        <h3 id="APIinfo"></h3>
        
        <!-- Server -->
        <label for="Server">Server:</label>
        <p>
          <input type="text" id="Server" name="txtServer" value="smpp.activexperts-labs.com" />
          : <input type="text" name="txtServerPort" style="width: 75px;" value="2775" />
        </p>
        
        <!-- System ID -->
        <label for="SystemID">System ID:</label>
        <p>
          <input type="text" id="SystemID" name="txtSystemID" />
        </p>
        
        <!-- Password -->
        <label for="Password">Password:</label>
        <p>
          <input type="text" id="Password" name="txtPassword" />
        </p>
        
        <!-- System Type -->
        <label for="SystemType">System Type:</label>
        <p>
          <input type="text" id="SystemType" name="txtSystemType" value="SMPP" />
        </p>  
        
        <!-- Recipient -->
        <label for="ToAddress">Recipient:</label>
        <p>
          <input type="text" id="ToAddress" name="txtToAddress" value="[ToAddress]" />
        </p>
        
        <!-- Message, Multipart, Flash -->
        <label for="Message">Message:</label>
        <p>
          <textarea id="Message" name="txtMessage" style="height:45px;">
            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>
        
        <!-- Empty row -->
        <div class="ax_clearRow"></div>
        
        <!-- Result -->
        <label for="Result"><b>Result:</b></label>
        <p>
          <input type="text" id="Result" name="txtResult"class="ax_FullWidth Bold" />
        </p>
        
        <!-- Message status -->
        <label for="Status">Message status:</label>
        <p>
          <input type="text" id="Status" name="txtMessageStatus"class="ax_FullWidth" />
        </p>
        
        <!-- Logfile -->
        <label for="Logfile">Logfile:</label>
        <p>
          <input type="text" id="Logfile" name="txtLogfile"class="ax_FullWidth" />
        </p>
      </form>
      <p>
        This demo uses the ActiveXperts SMS Component, an 
        <a href="http://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.
        <br />
         <a href="index.html">Back to main page</a>
      </p>
    </div><!-- /container -->
    <div class="ax_footer">
      <div class="ax_icon"></div>
      <p>
        © 2011 <a href="http://activexperts.com" target="_blank">
          Active<font color="#CCC000000">X</font>perts Software B.V.</a>
          All rights reserved.
        <small>
  <a href="http://activexperts.com/activexperts/contact"       target="_blank">Contact Us</a> |
  <a href="http://activexperts.com/activexperts/termsofuse"    target="_blank">Terms of Use</a> |
  <a href="http://activexperts.com/activexperts/privacypolicy" target="_blank">Privacy Policy</a>
        </small>
      </p>
    </div><!-- /footer -->
  </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.