Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts SMS Messaging Server Send, receive and automate SMS messages

Quicklinks


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

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

This demo project will ask the user to give a phone number and a message body on the command prompt. A GSM modem is required for this demo.

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 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/receive e-mail using SMS Component.

Step 3: Create the SMS Messaging Server API objects

Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor. On top of the ASP code, insert the following lines to declare and create the SMS Messaging Server API objects:

Set objConstants = Server.CreateObject("AxMmServer.Constants") Set objMessageDB = Server.CreateObject("AxMmServer.MessageDB")

Step 4: Test a small piece of ASP

Now, test if your new web site is working well with SMS Messaging Server 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:

  • 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:

<% Set objConstants = Server.CreateObject("AxMmServer.Constants") Set objMessageDB = Server.CreateObject("AxMmServer.MessageDB") %> <html> <head> <title>SMS Messaging Server Test</title> </head> <body> SMS Messaging Server Message Database:<br> <% = AxMessageDB.DatabaseConnectionString %><br> </body> </html>

And test it with your favorite browser. The result should be like this:

GSM ASP

(Click on the picture to enlarge)

Step 5: Create an SMS message

Now we are going to create an empty record in the database

' Create a new message Dim objMessage Set objMessage = objMessageDB.Create If (objMessageDB.LastError <> 0) Then strErrorDes = objMessageDB.GetErrorDescription(objMessageDB.LastError) objMessageDB.Close Response.Write strErrorDes Response.End End If

Step 6: Set SMS message information

Here we are going to setup the information of the message.

' Set the message type according to the users input If (Request("Type") = "SMS") Then objMessage.TypeID = objConstants.MESSAGETYPE_SMS Else objMessage.TypeID = objConstants.MESSAGETYPE_EMAIL End If objMessage.ChannelID = Request("Channel") objMessage.ToAddress = Request("To") objMessage.Body = Request("Body") ' Direction and status will always be the same. objMessage.DirectionID = objConstants.MESSAGEDIRECTION_OUT objMessage.StatusID = objConstants.MESSAGESTATUS_PENDING

Step 7: Save the SMS message

Now we are going to save the message into the database.

' Save the message to the message database. This way the Messaging server will ' pick it up and try to send it. objMessageDB.Save objMessage If (objMessageDB.LastError <> 0) Then strErrorDes = objMessageDB.GetErrorDescription(objMessageDB.LastError) objMessageDB.Close Response.Write strErrorDes Response.End End If

Appendix: Full source code

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

<% option explicit %> <html> <head> <META HTTP-EQUIV="CONTENT-Type" CONTENT="text/html;CHARSET=utf-8" > <title>ActiveXperts SMS Messaging Server ASP Samp le</title> <style> input, select{ width:150px; } </style> </head> <body> <% ' If any type of message was posted to this page, try to send it If Request("Type") <> "" Then ' Create COM objects Dim objConstants, objMessageDB, strErrorDes On Error Resume Next Set objConstants = Server.CreateObject("AxMmServer.Constants") Set objMessageDB = Server.CreateObject("AxMmServer.MessageDB") If Err.number <> 0 Then Response.Write("Unable initialize ActiveXperts Messaging Server components.") Response.End End If On Error Goto 0 ' Open message database objMessageDB.Open If (objMessageDB.LastError <> 0) Then strErrorDes = objMessageDB.GetErrorDescription(objMessageDB.LastError) Response.Write strErrorDes Response.End End If ' Create a new message Dim objMessage Set objMessage = objMessageDB.Create If (objMessageDB.LastError <> 0) Then strErrorDes = objMessageDB.GetErrorDescription(objMessageDB.LastError) objMessageDB.Close Response.Write strErrorDes Response.End End If ' Set the message type according to the users input If (Request("Type") = "SMS") Then objMessage.TypeID = objConstants.MESSAGETYPE_SMS Else objMessage.TypeID = objConstants.MESSAGETYPE_EMAIL End If objMessage.ChannelID = Request("Channel") objMessage.ToAddress = Request("To") objMessage.Body = Request("Body") ' Direction and status will always be the same. objMessage.DirectionID = objConstants.MESSAGEDIRECTION_OUT objMessage.StatusID = objConstants.MESSAGESTATUS_PENDING ' Save the message to the message database. This way the Messaging server will ' pick it up and try to send it. objMessageDB.Save objMessage If (objMessageDB.LastError <> 0) Then strErrorDes = objMessageDB.GetErrorDescription(objMessageDB.LastError) objMessageDB.Close Response.Write strErrorDes Response.End End If ' Close database objMessageDB.Close ' Inform the user of our success and display a welcome header. %> <h3>Message succesfully added to queue !</h3> <h2>Send another message using ASP</h2> <% Else ' If no message type was posted, display a welcome header %> <h2>Send a message using ASP</h2> <% End If %> <form action="default.asp" method="post"> <table width="700"> <tr><td>Type: </td><td> <select type="text" name="Type"> <option>SMS</option> <option>E-mail</option> </select></td></tr> <tr> <td>Channel: </td> <td> <input type="text" name="Channel" value="0"/> Use '0' to select the first available channel. </td> </tr> <tr> <td>To: </td> <td><input type="text" name="To"/> E-mail adress or <a href="http://www.activexperts.com/support/sms-messaging-server/index.asp?kb=Q8000020" target="_blank"> phone number </a> </td> </tr> <tr> <td valign="top">Body:</td> <td> <textarea name="Body" rows="3" cols="50"> ActiveXperts SMS Messaging Server test message </textarea> </td> </tr> <tr> <td> </td> <td><input type="submit" value="Send message"></td> </tr> </table> </form> </body> </html>

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.