ActiveXperts SMS Component

Quicklinks

ASP 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 a classic ASP page named 'Default.asp' to send SMS messges. This demo project will ask the user to give a phone number and a message body in the web interface. A GSM modem is required for this demo.

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 Web Site

First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on.

From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'. Right-click on the 'Web Sites' container and choose 'New->Web Site':

GSM ASP

(Click on the picture to enlarge)

The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:

  • Description - a friendly description of the new site;
  • IP / Port / Host Header - choose your preferred way to distinguish between other web sites on the server;
  • Path - select the directory that will store the ASP file(s);
  • Web Site Access Permissions - in the Web Site Access Permissions dialog, enable 'Read' and 'Run scripts (such as ASP)';

You're now able to write an ASP script to send SMS using SMS Component.

Step 3: Create the ActiveXperts SMS Component objects in ASP

Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor. We will use the 'objGsm' 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. On top of the ASP code, insert the following lines to declare and create the Gsm object, SmsMessage object and SmsConstants object.

<object runat="server" progid="AxSms.Gsm"        id="objGsm"></object>
<object runat="server" progid="AxSms.Constants"  id="objSmsConstants"></object>
<object runat="server" progid="AxSms.Message"    id="objSmsMessage"></object>

Step 4: Test a small piece of ASP

Now, test if your new web site is working well with the ActiveXperts SMS Component using your browser. If you are using Microsoft Internet Explorer, it is recommended to disable friendly error message because this default setting doesn't show any ASP error message, making it hard to debug if there are any problems. To disable friendly errors follow the next steps:

  • Choose' Internet Options' from the 'Tools' menu;
  • Select the 'Advanced' tab;
  • In the 'Browsing' folder, de-select the 'Show friendly HTTP error messages' option;
  • Click 'OK' to close the dialog.

Now, use the following piece of code in your DEFAULT.ASP page:

<!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 ASP Demo</title>
    <link rel="Stylesheet" type="text/css" href="css/SampleStylesheet.css" />  
    
    <object runat="server" progid="AxSms.Gsm" id="objGsm"></object>
    <object runat="server" progid="AxSms.Constants" id="objSmsConstants"></object>
    <object runat="server" progid="AxSms.Message" id="objSmsMessage"></object>

    <title>SMS Component Demo</title>
    
  </head>
  <body>
     SMS Component version: <% = objGsm.Version %><br>
     SMS Component License Status: <% = objGsm.LicenseStatus %>
  </body>
</html>

And test it with your favorite browser.

Step 5: Gather information

The following code will ask the user for the recipient telephone number and the content of the text message. If a PIN code is required, then it will be prompted you to enter one. This data will be stored in the 'objSmsMessage' object. If any error occours while trying to open the connection, the script will end.

' Message Settings
objSmsMessage.Clear()
objSmsMessage.ToAddress = Request("txtToAddress")
objSmsMessage.Body = Request("txtBody")
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT

Step 6: 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. 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

strMessageReference = objSmsMessage.Reference
strResult = objGsm.LastError & ": " & objGsm.GetErrorDescription(objGsm.LastError)

Appendix: Full source code

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

Here a screenshot of the web interface.

(Click on the picture to enlarge)

<object runat="server" progid="AxSms.Gsm"        id="objGsm"></object>
<object runat="server" progid="AxSms.Constants"  id="objSmsConstants"></object>
<object runat="server" progid="AxSms.Message"    id="objSmsMessage"></object>

<%
  strResult = "n/a"  

  Set fso = CreateObject("Scripting.FileSystemObject")
  
  strLogfile = fso.GetSpecialFolder(2) & "\ActiveXperts.Gsm.log"
  objGsm.LogFile = strLogfile
  'Windows default: "C:\Windows\Temp\ActiveXperts.Gsm.log"

  If(Request("btnSendMessage") <> "") Then
    Dim obj, strMessageReference, strName, strPincode, iDeviceSpeed

    strName      = Request("ddlDevices")
    strPincode   = Request("txtPincode")
    iDeviceSpeed = Request("ddlDeviceSpeed")

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

    If (objGsm.LastError <> 0) Then
      strResult = objGsm.LastError & ": " & objGsm.GetErrorDescription(objGsm.LastError)
      objGsm.Close()
    Else
      ' Message Settings
      objSmsMessage.Clear()
      objSmsMessage.ToAddress = Request("txtToAddress")
      objSmsMessage.Body = Request("txtBody")
      objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT

      Dim iMultipart

      If (Request("cbxMultipart") <> "") Then
        iMultipart = objSmsConstants.MULTIPART_OK
      Else
        iMultipart = objSmsConstants.MULTIPART_TRUNCATE
      End If

      If (Request("cbxFlash") <> "") Then
       objSmsMessage.DataCoding = objSmsMessage.DataCoding or objSmsConstants.DATACODING_FLASH
      End If

      ' Send the message !
      objGsm.SendSms objSmsMessage, iMultipart, 10000

      strMessageReference = objSmsMessage.Reference
      strResult = objGsm.LastError & ": " & objGsm.GetErrorDescription(objGsm.LastError)

      objGsm.Close()      
    End If    
  End If
%>

<!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>
  </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 ASP 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 action="gsm.asp" method="post">
        <h2>SMS Component:</h2>
        <h3>Build: <% = objGsm.Build %>; Module: <% = objGsm.Module %></h3>

        <!-- Device -->
        <label for="Devices">Device:</label>
        <p>
          <select id="Devices" name="ddlDevices">
          <%
            Dim strDevice, strPort
            strDevice = objGsm.FindFirstDevice()
            
            While (objGsm.LastError = 0)
              Response.Write "<option value=""" & strDevice & """>" & strDevice & "</option>"
              strDevice = objGsm.FindNextDevice()
            Wend
            
            ' Add COM ports.
            ' Gets first COM port.
            strPort = objGsm.FindFirstPort()
            While (objGsm.LastError = 0)
                Response.Write "<option value=""" & strPort & """>" & strPort & "</option>"
                'Gets next COM port.
                strPort = objGsm.FindNextPort()
            Wend
          %>
          </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>
        
        <!-- 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, 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>
        
        <!-- Empty row -->
        <div class="ax_clearRow"></div>

        <!-- Send button -->
        <div class="ax_clearLabel"></div>
        <p>
          <input type="submit" name="btnSendMessage" value="Send SMS Message!" />
        </p>

        <!-- Result -->
        <label for="Result"><b>Result:</b></label>
        <p>
          <input type="text" id="Result" name="txtResult"class="ax_FullWidth" 
            style="font-weight: bold;" value="<% = strResult %>" />
        </p>
        
        <!-- Logfile -->
        <label for="Logfile">Logfile:</label>
        <p>
          <input type="text" id="LogFile" name="txtLogFile"class="ax_FullWidth" 
            value="<% = strLogfile %>" />
        </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="Default.asp">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="#c00">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.