Shortcut Menu

Skip

Main Navigation

Choose your language


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

Quicklinks


VBScript 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 a Visual Basic Script to send SMS messages. This demo project will ask the user to give a phone number and a message body on the command prompt.

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 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.

You're now able to write a more advanced VBScript script to send/receive SMS using SMS Component.

Step 4: Declare and create the ActiveXperts SMS Component objects

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:

The following code will show you how to declare and create the GSM 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.

Set objSmpp                   = CreateObject ( "AxSms.Smpp" )
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. You will also be asked to enter the username and the password for the SMPP gateway. This data will be stored in the 'objSmsMessage' object.

' Set SMPP Server
strServer   = ReadInput ( "Enter hostname of SMPP server", "smpp.activexperts-labs.com", False )

' Set SMPP ServerPort
nPort       = ReadInput ( "Enter portnumber of SMPP server", 2775, False )
 
' Set SMPP SystemID
strUsername = ReadInput ( "Enter account systemID", strUsername, False )

' Set SMPP Password
strPassword = ReadInput ( "Enter account password", strPassword, False )

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.

objSmpp.SubmitSms( objMessage )
Wscript.Echo "SubmitSms, result: " & objSmpp.LastError

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
'
' Send a text SMS message through a SMPP provider.
'
' (c) Copyright ActiveXperts Software - www.activexperts.com
'
' ********************************************************************


Option Explicit

' Declare objects
Dim objSmpp, objMessage, objSmsConstants, objDeliveryStatus

' Declare Variables
Dim strServer, nPort, nTimeout, strUsername, strPassword, strReference

' Create objects
Set objSmpp                   = CreateObject ( "AxSms.Smpp" )
Set objMessage                = CreateObject ( "AxSms.Message" )
Set objSmsConstants           = CreateObject ( "AxSms.Constants" )

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

'Get username and password for ActiveXperts SMPP Demo account
GetSMSDemoAccountInfo strUsername, strPassword

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

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

' Set SMPP Server
strServer   = ReadInput ( "Enter hostname of SMPP server", "smpp.activexperts-labs.com", False )

' Set SMPP ServerPort
nPort       = ReadInput ( "Enter portnumber of SMPP server", 2775, False )

' Set SMPP SystemID
strUsername = ReadInput ( "Enter account systemID", strUsername, False )

' Set SMPP Password
strPassword = ReadInput ( "Enter account password", strPassword, False )

nTimeout = 2000

' Connect to smpp provider
objSmpp.Connect strServer, nPort, nTimeout
WScript.Echo "Connect, result: " & objSmpp.LastError
If ( objSmpp.LastError <> 0 ) Then 
  WScript.Sleep 3000
  WScript.Quit
End If 

objSmpp.Bind objSmsConstants.SMPP_BIND_TRANSCEIVER, strUsername, strPassword, "", 
             objSmsConstants.SMPP_VERSION_34, 0, 0, "", nTimeout
WScript.Echo "Bind, result: " & objSmpp.LastError
If ( objSmpp.LastError <> 0 ) Then
  objSmpp.Disconnect
  WScript.Sleep 3000
  WScript.Quit
End If

' Message: set all properties
objMessage.Clear
objMessage.FromAddress        = "+316121345678"
objMessage.ToAddress          = ReadInput( "Enter Recipient", "+", False )
objMessage.Body               = ReadInput ( "Enter the message text you want to send", _
                                "Hello from the ActiveXperts SMS Component!", False )
objMessage.BodyFormat         = objSmsConstants.BODYFORMAT_TEXT   

' Send the message 
WScript.Echo "Sending the message..."

objMessage.RequestDeliveryReport = True

objSmpp.SubmitSms( objMessage )
Wscript.Echo "SubmitSms, result: " & objSmpp.LastError
If( objSmpp.LastError <> 0 ) Then
  objSmpp.Unbind
  objSmpp.Disconnect
  WScript.Sleep 3000
  WScript.Quit  
End If

Do While objSmpp.WaitForSmsUpdate(1000)
  Set objMessage = objSmpp.FetchSmsUpdate
  Wscript.Echo "FetchSmsUpdate, result: " & objSmpp.LastError
  If objSmpp.LastError = 0 Then
     Exit Do
  End If
  WScript.Sleep 100
Loop

strReference = objMessage.Reference

' Show the result
If( objSmpp.LastError <> 0 ) Then
  objSmpp.Unbind
  objSmpp.Disconnect
  WScript.Sleep 3000
  WScript.Quit
End If	 

' Show the Message Reference
WScript.Echo "Message successfully submitted" & vbCrLf & "Message reference : " & strReference

Dim bGo
bGo = True

While bGo 'Keeps going until Delivery report was found
  Set objMessage = objSmpp.ReceiveMessage
  WScript.Echo "ReceiveMessage, result: " & objSmpp.LastError
  While objSmpp.LastError = 0   

    If objMessage.SmppIsDeliveryReport Then
      WScript.Echo "Delivery rpt for: " & Left(objMessage.Body, InStr(objMessage.Body, " ")) & _
        "State: " & Mid(objMessage.Body, InStr(objMessage.Body, "stat:")+5, 7)  
        bGo = False
    Else
      WScript.Echo "  Message to: " & objMessage.ToAddress
      WScript.Echo "  Message body: " & objMessage.Body      
    End If
    Set objMessage = objSmpp.ReceiveMessage
    WScript.Echo "ReceiveMessage, result: " & objSmpp.LastError
  Wend
  objSmpp.Sleep 3000
    
  If( bGo ) Then
    Wscript.Echo "No delivery report received yet."
  End If
Wend

objSmpp.Unbind
objSmpp.Disconnect

WScript.Echo "Disconnected."
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
' ***************************************************************************
Function GetSMSDemoAccountInfo(ByRef strSystemID, ByRef strPassword)
  Dim objRegistery, objFileSystem, objTextFile
  Dim strInstallRoot, strAccountFile
  
  Set objRegistery            = CreateObject("WScript.Shell")
  Set objFileSystem           = CreateObject("Scripting.FileSystemObject")
  
  strInstallRoot              = 
    objRegistery.RegRead("HKLM\SOFTWARE\\ActiveXperts\\SMS Component\\InstallRoot")
  strAccountFile              = strInstallRoot
  strAccountFile              = strAccountFile & "\\Utilities\\activexperts-labs.txt"

  If objFileSystem.FileExists(strAccountFile) Then
    Set objTextFile           = objFileSystem.OpenTextFile(strAccountFile)
                                objTextFile.ReadLine 'Skip firstline
    strSystemID               = objTextFile.ReadLine '2nd line SystemID
    strPassword               = objTextFile.ReadLine '3rd line Password
    objTextFile.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.