ActiveXperts SMS Component

Quicklinks

VBScript 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 create a VBScript 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 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. Read more about the ActiveXperts SMS Component on the product home page.

Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

Step 3: Create the ActiveXperts SMS Component objects in VBScript

Create a new VBScript file called Demo.vbs. :

Create the objects like this:

Set objHttp                   = CreateObject ( "AxSms.Http" )
Set objMessage                = CreateObject ( "AxSms.Message" )
Set objSmsConstants           = CreateObject ( "AxSms.Constants" )

Now, add the following lines to the file to have your fist SMS Component VBScript program:

WScript.Echo "Version: " & objHttp.Version
WScript.Echo "License Status: " & objHttp.LicenseStatus

Step 4: Declare and create the ActiveXperts SMS Component objects

Create a new VBScript script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor. We will use the 'objHttp' 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 Http object, SmsMessage object and SmsConstants object.

' Create Objects
Set objHttp                   = CreateObject ( "AxSms.Http" )
Set objMessage                = CreateObject ( "AxSms.Message" )
Set objSmsConstants           = CreateObject ( "AxSms.Constants" )

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.

objMessage.ToAddress        = ReadInput ( "Enter recipient address", "+", False )
objMessage.Body             = ReadInput ( "Enter the message", "Hello from ActiveXperts!", False )

Step 6: Send SMS messages

You can now send SMS messages.

The following VBScript code shows how to send a SMS message using an HTTP Based SMS solution provider:

WScript.Echo objHttp.SendSms ( objMessage )
WScript.Echo "SendSms, result: " & objHttp.LastError
WScript.Echo "Response: " & objHttp.LastResponseCode

Appendix: Full source code

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

' ********************************************************************
'
' ActiveXperts SMS Component
'
' Sends an single SMS message through an SMS/HTTP connection.
'
' (c) Copyright ActiveXperts Software - www.activexperts.com
'
' ********************************************************************


Option Explicit

' Declare objects
Dim objHttp, objMessage, objSmsConstants
Dim strUsername, strPassword

' Create Objects
Set objHttp                   = CreateObject ( "AxSms.Http" )
Set objMessage                = CreateObject ( "AxSms.Message" )
Set objSmsConstants           = CreateObject ( "AxSms.Constants" )

' Display SMS Component Version
WScript.Echo "SMS Component Version " & objHttp.Version & "; " &_
                     "Build " & objHttp.Build & "; Module " & objHttp.Module

' Display if the ActiveXperts SMS Component is registered.
WScript.Echo "License Status: " & objHttp.LicenseStatus & vbCrLf 

' Set Logfile
Dim fso: Set fso              = CreateObject("Scripting.FileSystemObject")
objHttp.LogFile               = fso.GetSpecialFolder(2) & "\HTTP_sendsms_text.txt"
WScript.Echo "Log file can be found here:"
Wscript.Echo objHttp.LogFile

GetSmsDemoAccountInfo strUsername, strPassword

' Set ProviderHost
objHttp.Url = "post.activexperts-labs.com:8080/sendsms/default.asp?" & _
	"username="& strUsername &"&password=" & strPassword & "&text=" & _
    objSmsConstants.HTTP_PLACEHOLDER_BODY & "&to=" & objSmsConstants.HTTP_PLACEHOLDER_TOADDRESS   

' SMS Message Properties
objMessage.BodyFormat         = objSmsConstants.GSM_MESSAGEFORMAT_TEXT

objMessage.ToAddress  = ReadInput ( "Enter recipient address", "+", False )
objMessage.Body       = ReadInput ( "Enter the message", "Hello from ActiveXperts!", False )

WScript.Echo objHttp.SendSms ( objMessage )
WScript.Echo "SendSms, result: " & objHttp.LastError
WScript.Echo "Response: " & objHttp.LastResponseCode

WScript.Echo "Ready"
WScript.Sleep 3000

' ***************************************************************************
' Function ReadInput
' ***************************************************************************
Function ReadInput( ByVal strTitle, ByVal strDefault, ByVal bAllowEmpty )

  Dim strInput, strReturn

  Do
     strInput = inputbox( strTitle, "Enter value", strDefault )
     If ( strInput <> "" ) Then
          strReturn = strInput
     End If
  Loop until strReturn <> "" Or bAllowEmpty

  ReadInput = strReturn
End Function

Function GetSmsDemoAccountInfo(BYREF strSystemID, BYREF strPassword)

  Dim objRegistery, objFileSystem, objFile
  Dim strInstallRoot, strAccountFile

  Set objRegistery            = CreateObject("WScript.Shell")
  Set objFileSystem           = CreateObject("Scripting.FileSystemObject")
  strInstallRoot              = 
      objRegistery.RegRead("HKLM\SOFTWARE\\ActiveXperts\\SMS Component\\InstallRoot")

  If (strInstallRoot <> "") Then
    strAccountFile            = strInstallRoot & "\\Utilities\\activexperts-labs.txt"
    
    If Not(objFileSystem.FileExists(strAccountFile)) Then
      WScript.Echo "Account details for the ActiveXperts Demo gatway not found."
      WScript.Quit
    End If    
    
    Set objFile               = objFileSystem.OpenTextFile(strAccountFile)    
      objFile.ReadLine               '1st line is a comment line; skip it
    strSystemID               = objFile.ReadLine '2nd line is the SystemID
    strPassword               = objFile.ReadLine '3rd line is the password
    objFile.Close
    
  End If
End Function

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.