ActiveXperts SMS Messaging Server Send, receive and automate SMS messages

Quicklinks


Send an SMS message using the SMS Messaging Server API - Visual Basic .NET

SMS Messaging Server is an SMS messaging framework that enables companies to send, receive and process SMS- and e-mail messages. The framework is designed support virtually any scenario where low-and high volume SMS messaging is required. Use SMS Messaging Server in the following scenarios:

  • Mobile users query a database; results are sent back via SMS or e-mail;
  • Mobile users receive important information via SMS or e-mail while they are away from the office;
  • Stock prices are sent automatically via SMS and/or e-mail, daily;
  • Remote workers can update their worksheet from a remote location trough SMS;
  • ICT administrators restart/reboot servers and/or daemons from remote by SMS;
  • Setup an SMS voting system, supporting SMS and/or e-mail;
  • Etc.

SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into VBScript projects.

Step 1: Download and install SMS Messaging Server

Download ActiveXperts SMS Messaging Server from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Visual Basic .NET Project

Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):

Visual Basic dotNET

(Click on the picture to enlarge)

Step 3: Refer to the SMS Messaging Server Library and create the objects

Now that a new project has been created, you must add a reference to the SMS Messaging Server API in the project to be able to use the it. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveXperts SMS Messaging Server API Type Library' as shown in the following picture:

Visual Basic .NET

(Click on the picture to enlarge)

Click 'OK' to close the 'Add Reference' dialog.

On top of your code, type the following line to use the SMS Messaging Server API namespace:

Imports AXMMCFGLib

In your Main function, declare and create the following objects:

Public objMessageDB As IXMessageDB
Public objConstants As IXConstants

Step 4: Send an SMS Message

You can now send an SMS message.

The following code shows how to send a SMS message:

Imports AXMMCFGLib

Module Module1

    Public objMessageDB As IXMessageDB
    Public objConstants As IXConstants


    Sub Main()
        Dim numRecordID As Integer

        objMessageDB = New XMessageDB()
        objConstants = New XConstants()

        objMessageDB.Open()
        If (objMessageDB.LastError <> 0) Then
            Console.WriteLine("Unable to open database, error: " & objMessageDB.LastError)
            Exit Sub
        End If

        numRecordID = CreateSmsMessage()
        If (numRecordID > 0) Then
            PrintMessage(numRecordID)
        End If

        objMessageDB.Close()
        Console.WriteLine("Ready.")
    End Sub


    Function CreateSmsMessage()

        CreateSmsMessage = 0

        Dim objMessage As IXMessage

        objMessage = objMessageDB.Create()
        If (objMessageDB.LastError <> 0) Then
            Console.WriteLine("Create failed, error: " & objMessageDB.LastError)
            Exit Function
        End If
        Console.WriteLine("Message successfully created, recordID: " & objMessage.ID)

        objMessage.Direction = objConstants.MESSAGEDIRECTION_OUT
        objMessage.Type = objConstants.MESSAGETYPE_SMS
        objMessage.Status = objConstants.MESSAGESTATUS_PENDING
        objMessage.ChannelID = 0
        objMessage.ScheduledTime = ""
        objMessage.Recipient = "+31624896641"
        objMessage.Body = "SMS Messaging Server - Test SMS Message"
        objMessageDB.Save(objMessage)

        If (objMessageDB.LastError <> 0) Then
            Console.WriteLine("Update message failed, error: " & objMessageDB.LastError)
            Exit Function
        End If

        CreateSmsMessage = objMessage.ID
    End Function


    Sub PrintMessage(ByVal numID)
        Dim objMessage As XMessage

        objMessage = objMessageDB.Load(numID)
        If (objMessageDB.LastError <> 0) Then
            Console.WriteLine("Failed to load message " & numID)
            Exit Sub
        End If

        Console.WriteLine("  ID               : " & objMessage.ID)
        Console.WriteLine("  Direction        : " & objMessageDB.GetDirectionDescription(objMessage.Direction))
        Console.WriteLine("  Type             : " & objMessageDB.GetTypeDescription(objMessage.Type))
        Console.WriteLine("  Status           : " & objMessageDB.GetStatusDescription(objMessage.Status))
        Console.WriteLine("  StatusDetails    : " & objMessageDB.GetStatusDetailsDescription(objMessage.StatusDetails))
        Console.WriteLine("  ChannelID        : " & objMessage.ChannelID)
        Console.WriteLine("  MessageReference : " & objMessage.MessageReference)
        Console.WriteLine("  ScheduledTime    : " & objMessage.GetScheduledTimeString())
        Console.WriteLine("  LastUpdate       : " & objMessage.GetLastUpdateString())
        Console.WriteLine("  Sender           : " & objMessage.Sender)
        Console.WriteLine("  Recipient        : " & objMessage.Recipient)
        Console.WriteLine("  Subject          : " & objMessage.Subject)
        Console.WriteLine("  Body             : " & objMessage.Body)
        Console.WriteLine("  Trace            : " & objMessage.Trace)
    End Sub

End Module