ActiveXperts SMS Messaging Server

Quicklinks

Create an SMS message using the SMS Messaging Server API - Delphi

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 your own projects.


Introduction

In this example we are going to create a Delphi sample page to create an SMS using the ActiveXperts SMS Messaging Server API. The SMS Messaging Server service will send the message you created in the database.

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 Delphi Project

Launch Borland Delphi from the Start menu. In our example we use Delphi 2010. Choose 'New' from the 'File' menu and select your preferred kind of application, for instance: 'VCL Forms Application - Delphi'. A new Form is displayed in the workspace.

Borland Delphi

(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 Library in the project to be able to use the SMS Messaging Server objects. To do so, choose 'Import Component...' from the 'Component' menu. The Import Components' dialog appears. Select 'Import a Type Library':

Borland Delphi

(Click on the picture to enlarge)

In the 'Registered Type Libraries' page, select 'ActiveXperts SMS Messaging Server Type Library' and click 'Next':

Borland Delphi

(Click on the picture to enlarge)

In the 'Components' page, leave all fields default and click 'Next':

Borland Delphi

(Click on the picture to enlarge)

In the 'Install' page, select 'Create Unit' and click 'Next':

Borland Delphi

(Click on the picture to enlarge)

The interface code is generated now and is shown in the AXMMCFGLib_TLB tab of the project.

Step 4: Declare and create the object

From the Project Manager, open Unit1.bas and add the AXMMCFGLib_TLB to the 'Uses' statement to refer to the SMS Messaging Server Library:

Borland Delphi

(Click on the picture to enlarge)

In the 'private' or 'public' section, declare the following objects:

objMessageDB : IXMessageDB; objConstants : IXConstants;

You can now create the objects, for instance in the 'FormCreate' function:

objMessageDB := CoXMessageDB.Create(); objConstants := CoXConstants.Create();

Step 5: Create the SMS Message

The following code will create the SMS Message.

// Create a new message objMessage := IDispatch (objMessageDb.Create()) as IXMessage; Writeln('Create message result: ', InttoStr(objMessageDb.LastError), ' ', objMessageDb.GetErrorDescription(objMessageDb.LastError)); if (objMessageDb.LastError <> 0) then begin objMessageDb.Close(); Exit; end;

Step 6: Save the SMS Message

The following code will save the SMS message into the database:

// Save the message to the message database vt := objMessage; objMessageDB.Save (vt); Writeln('Save result: ', InttoStr(objMessageDb.LastError), ' ', objMessageDb.GetErrorDescription(objMessageDb.LastError));

Appendix: Full source code

The following code shows how to send an SMS message using the SMS Messaging Server API:

{******************************************************************************} { } { ActiveXperts } { } { SMS Messaging Server: create SMS } { } {******************************************************************************} program CreateEMAIL; {$APPTYPE CONSOLE} uses SysUtils, ActiveX, AXMMCFGLib_TLB in '..\typelib-imports\AXMMCFGLib_TLB.pas'; {= V A R I A B L E S ==========================================================} var objMessageDb : XMessageDB; objConstants : XConstants; strRecipient, strBody:string; objMessage: XMessage; vt:OleVariant; {= P R O G R A M ==============================================================} begin // Create API objects objMessageDB := CoXMessageDB.Create(); objConstants := CoXConstants.Create(); // Open message database objMessageDb.Open(True); Writeln('Open result: ', InttoStr(objMessageDb.LastError), ' ', objMessageDb.GetErrorDescription(objMessageDb.LastError)); if (objMessageDb.LastError <> 0) then Exit; // Get message info from user Writeln('Enter recipient''s phone number: '); Readln(strRecipient); Writeln('Enter body of the message:'); Readln(strBody); // Create a new message objMessage := IDispatch (objMessageDb.Create()) as IXMessage; Writeln('Create message result: ', InttoStr(objMessageDb.LastError), ' ', objMessageDb.GetErrorDescription(objMessageDb.LastError)); if (objMessageDb.LastError <> 0) then begin objMessageDb.Close(); Exit; end; // Set the properties for the message object Writeln('RecordID: ',objMessage.ID); objMessage.DirectionID := objConstants.MESSAGEDIRECTION_OUT; objMessage.typeID := objConstants.MESSAGETYPE_SMS; objMessage.StatusID := objConstants.MESSAGESTATUS_PENDING; objMessage.ChannelID := 0; objMessage.ScheduledTime := ''; objMessage.ToAddress := strRecipient; objMessage.Body := strBody; // Save the message to the message database vt := objMessage; objMessageDB.Save (vt); Writeln('Save result: ', InttoStr(objMessageDb.LastError), ' ', objMessageDb.GetErrorDescription(objMessageDb.LastError)); // Close message database objMessageDB.Close; write('Press ENTER to close the program'); readln; end.

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-messaging-server. 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 SMS Messaging Server 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.