Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts SMS Component Add SMS capabilities to any Windows or .NET application

Quicklinks


ColdFusion 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 use create a ColdFusion project 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: Download and install the ActiveXperts SMS Component

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 a new ColdFusion document

Create a new blank webdocument with the ".cfm" extention. First of all we are going to build the form whitch commands and properties of the device can be filled in. Then we are going to make a source code that connects to the device.

Step 3: Implementation

To use SMPP in ColdFusion, we need to use the Smpp object for sending/receiving SMS messages. We also need the constants object. Make sure the IUSR has the proper rights to create these activeX objects!

<cfobject type="com" Action="Create"class="ax_AxSms.Smpp"          name="objSmpp">
<cfobject type="com" Action="Create"class="ax_AxSms.Message"    name="objSmsMessage">
<cfobject type="com" Action="Create"class="ax_AxSms.Constants"  name="objSmsConstants">

Step 4: Create a form

In case you're sending your SMS messages using a SMPP provider, you're dealing with some sort of a gateway. So in order to send a message you need to be connected to this gateway first. Therefore, create a simple ColdFusion form to collect the following data:

  • The servername
  • The serverport
  • The system ID ( username )
  • The password

Also collect the following data:

  • The recipient
  • The message data

Create a simple form to collect this information from the user. You can configure the required fields as required fields in ColdFusion. If the user does not fill in these fields properly, a messagebox is shown and the form will not be submitted. Make sure you create a ColdFusion form, not a plain HTML form.

Step 5: Gather information

The following code will ask the user for the recipient telephone number and the content of the text message. This data will be stored in the 'objSmsMessage' object. If any error occours while trying to open the connection, the script will end.

objSmsMessage.Clear();
objSmsMessage.RequestDeliveryReport = true;
objSmsMessage.ToAddress = Form.txtToAddress;
objSmsMessage.Body = Form.txtMessage;
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;

Step 6: Send SMS message

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

objSmpp.SubmitSms(objSmsMessage, iMultipart);

Appendix: Full source code

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

<cfobject type="com" Action="Create"class="ax_AxSms.Smpp"          name="objSmpp">
<cfobject type="com" Action="Create"class="ax_AxSms.Message"    name="objSmsMessage">
<cfobject type="com" Action="Create"class="ax_AxSms.Constants"  name="objSmsConstants">

<cfregistry action = "get" 
  branch = "HKEY_LOCAL_MACHINE\SOFTWARE\ActiveXperts\SMS Component"
  entry = "InstallRoot"
  variable = "strInstrallRoot"
  type = "string"> 

<cfscript> 
  strResult = "n/a";
  strLastResponse = "";
  strMessageStatus = "";
  objSmpp.LogFile = "C:\Windows\Windows\Temp\ActiveXperts.Smpp.log";
  
  ArrAccountInfo = GetSmsDemoAccountInfo();
  
  if (IsDefined("Form.btnSendMessage"))
  {
    objSmpp.Connect(Form.txtServer, Form.txtServerPort, 5000);
    if (objSmpp.LastError != 0)
    {
      strResult = objSmpp.LastError & ": " & objSmpp.GetErrorDescription(objSmpp.LastError);
    }
    else
    {
      iSystemMode = objSmsConstants.SMPP_BIND_TRANSCEIVER;
      iVersion = objSmsConstants.SMPP_VERSION_34;
      objSmpp.Bind(iSystemMode, Form.txtSystemID, Form.txtPassword, 
                                Form.txtSystemType, iVersion, 0, 0, "", 2000);
      
      if (objSmpp.LastError != 0)
      {
        strResult = objSmpp.LastError & ": " & objSmpp.GetErrorDescription(objSmpp.LastError);
      }
      else
      {
        bSearchDeliveryReport = true;
        objSmsMessage.Clear();
        objSmsMessage.RequestDeliveryReport = true;
        objSmsMessage.ToAddress = Form.txtToAddress;
        objSmsMessage.Body = Form.txtMessage;
        objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;
        
        if (IsDefined("Form.cbxFlash"))
        {
          objSmsMessage.DataCoding = objSmsMessage.DataCoding Or objSmsConstants.DATACODING_FLASH;
        }
        
        if (IsDefined("Form.cbxMultipart"))
        {
          iMultipart = objSmsConstants.MULTIPART_OK;
        }
        else
        {
          iMultipart = objSmsConstants.MULTIPART_TRUNCATE;
        }
        
        objSmpp.SubmitSms(objSmsMessage, iMultipart);
        
        if (objSmpp.LastError != 0)
        {
          strResult = objSmpp.LastError & ": " & objSmpp.GetErrorDescription(objSmpp.LastError);
        }
        else
        {
          while (objSmpp.WaitForSmsUpdate(1000))
          {
            objMessage = objSmpp.FetchSmsUpdate();
            if (objSmpp.LastError == 0)
            {
              objSmpp.Sleep(100);
              break;
            }
          }
          
          strMessageReference = objMessage.Reference;
          
          while (bSearchDeliveryReport)
          {
            objMessage = objSmpp.ReceiveMessage();
            while (objsmpp.LastError == 0)
            {
              if (objMessage.SmppIsDeliveryReport)
              {
                if (strMessageReference == Mid(objMessage.Body, Find("id:",objMessage.Body)+3,8))
                {
                  
                  strMessageStatus = Mid(objMessage.Body, Find("stat:", objMessage.Body) + 5, 7);
                  bSearchDeliveryReport = false;
                  
                  break;   
                }
              }
              objMessage = objSmpp.ReceiveMessage();
            }
          }
          strResult = objSmpp.LastError & ": " & objSmpp.GetErrorDescription(objSmpp.LastError);
        }
      }
    }
  }
  
  function GetSmsDemoAccountInfo ()
  {
    // 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
  
    strDirectory = strInstrallRoot & "\Utilities\activexperts-labs.txt";
    
    strArr = ArrayNew(1);
    objFile = FileOpen(strDirectory, "read");
    FileReadLine(objFile);
    ArrayAppend(strArr, FileReadLine(objFile));
    ArrayAppend(strArr, FileReadLine(objFile));
    FileClose(objFile);
    
    return strArr;
  }
</cfscript>
  
<!--- HTML-CSS layout includes, no code there! --->
<!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 Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
</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_container">
      <h1>SMS Component Coldfusion 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.<br />
      </p>
      
      <form action="smpp.cfm" method="post">
      <cfoutput>
        <h2>SMS Component:</h2>
        <h3>Build: #objSmpp.Build#; Module: #objSmpp.Module#</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" value="#ArrAccountInfo[1]#" />
        </p>
        
        <!-- Password -->
        <label for="Password">Password:</label>
        <p>
          <input type="text" id="Password" name="txtPassword" value="#ArrAccountInfo[2]#" />
        </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="submit" name="btnSendMessage" 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" 
              value="#strResult#" />
        </p>
        
        <!-- Message status -->
        <label for="Status">Message status:</label>
        <p>
          <input type="text" id="Status" name="txtMessageStatus"class="ax_FullWidth" 
              value="#strMessageStatus#" />
        </p>
      </cfoutput>
      </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.cfm">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.