ActiveXperts SMS Component

Quicklinks

ColdFusion sample - Send SMS text through an HTTP 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 HTTP 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 HTTP-POST in ColdFusion, we need to use the Http and SmsMessage objects for sending SMS messages. We also need the constants object.

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

Step 4: Create a form

To send a SMS message using HTTP the following data is required by the component:

  • A url to submit the message to.
  • The server port.
  • The responses the server might return.
  • The message.
  • The recipient.

Step 5: Collect the submitted data and send the message.

If the form is submitted and the data is succesfully collected, the message needs to be sent to the recipient. The Message object and the HttpPost object need to be configured to send a message. The message object contains all message data like the message type, the message body and the recipient number. The url, the port, the errorresponse and so on are stored in the HttpPost object. If all required information is submitted to the HttpPost object, a connection is made.

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.

objHttp.SendSms(obj, objSmsConstants.MULTIPART_OK);

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.Http"       name="objHttp" >
<cfobject type="com" Action="Create"class="ax_AxSms.Constants"  name="objSmsConstants">
<cfobject type="com" Action="Create"class="ax_AxSms.Message"    name="objSmsMessage">

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

<cfscript> 
  strResult = "n/a";
  strLastResponse = "";
  objHttp.LogFile = "C:\Windows\Temp\ActiveXperts.Http.log";
  
  if (IsDefined("Form.btnSendMessage"))
  {
    objSmsMessage.Clear();   

    objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;
    
    objSmsMessage.Body = Form.txtBody;
    objSmsMessage.ToAddress = Form.txtToAddress;
    
    objHttp.Clear();
    objHttp.Url = Form.txtUrl;
         
    obj = objSmsMessage;
    objHttp.SendSms(obj, objSmsConstants.MULTIPART_OK);
    
    strResult = objHttp.LastError & ': ' & objHttp.GetErrorDescription(objHttp.LastError);
    strLastResponse = objHttp.LastResponseCode;    
  }
  
  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";
    
    objFile = FileOpen(strDirectory, "read");
    FileReadLine(objFile);
    strAccount = FileReadLine(objFile);
    strPassword = FileReadLine(objFile);
    FileClose(objFile);
    
    strInfo = "post.activexperts-labs.com:8080/sendsms/default.asp";
    strInfo = strInfo & "?username=" & strAccount;
    strInfo = strInfo & "&password=" & strPassword;
    strInfo = strInfo & "&text=" & objSmsConstants.HTTP_PLACEHOLDER_BODY;
    strInfo = strInfo & "&to=" & objSmsConstants.HTTP_PLACEHOLDER_TOADDRESS;
    
    return strInfo;
  }
</cfscript> 



<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 HTTP Sample</h1>
      <hr />
      <p>
      The HTTP protocol is used for medium volume SMS messaging. Messages are first routed to the 
      service provider via Internet/VPN. The provider delivers the messages to the recipient's 
      phone. If you are not subscribed to a provider, use the ActiveXperts gateway to send 10 SMS 
      messages for free. 
      </p>
      <form action="http.cfm" method="post">
      <cfoutput>
        <h2>SMS Component:</h2>
        <h3>Build: #objHttp.Build#; Module: #objHttp.Module#</h3>
      
        <!-- Connection URL -->
        <label for="Url">Connection URL:</label>
        <p>
          <input type="text" id="Url" name="txtUrl"class="ax_FullWidth" 
            value="#GetSmsDemoAccountInfo()#" />
        </p>
        
        <!-- Empty row -->
        <div class="ax_clearRow"></div>
        
        <!-- 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 -->
        <label for="Body">Body:</label>
        <p>
          <textarea id="Body" name="txtBody" style="height:55px;">
            Hello world send from ActiveXperts SMS Component!
          </textarea>
        </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>
        
        <!-- Last Response -->
        <label for="Response">Last Response:</label>
        <p>
          <input type="text" id="Response" name="txtLastResponse"class="ax_FullWidth" 
            value="#strLastResponse#" />
        </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.