You are here:
ActiveXperts.com > SMS Component > How to Use the ActiveXperts SMS Component > HTTP/SMS > ASP 2.x
Quicklinks
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.
In this example we are going to create a classic ASP 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.
Download the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
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':
The 'Web Site Creation Wizard' is shown, guiding you through the process of creating a new web site. Provide all necessary information:
You're now able to write an ASP script to send and receive SMS messages using the ActiveXperts SMS Component.
Create a new ASP 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.
<object runat="server" progid="AxSms.Http" id="objHttp"></object> <object runat="server" progid="AxSms.Message" id="objSmsMessage"></object> <object runat="server" progid="AxSms.Constants" id="objSmsConstants"></object>
Now, test if your new web site is working well with the ActiveXperts SMS Component 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:
Now, use the following piece of code in your DEFAULT.ASP page:
<object runat="server" progid="AxSms.Http" id="objHttp"></object>
<object runat="server" progid="AxSms.Constants" id="objSmsConstants"></object>
<html>
<head>
<title>SMS Component Demo</title>`
</head>
<body>
SMS Component version: <% = objHttp.Version %><br>
SMS Component License Status: <% = objHttp.LicenseStatus %>
</body>
</html>
And test it with your favorite browser. The result should be like this:
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.
If(Request("btnSendMessage") <> "") Then
objSmsMessage.Clear()
objSmsMessage.Body = Request("txtBody")
objSmsMessage.ToAddress = Request("txtToAddress")
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT
The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects.
Set obj = objSmsMessage objHttp.SendSms obj, objSmsConstants.MULTIPART_OK
Following you can find the full source code which is also included in the ActiveXperts SMS Component package.
<object runat="server" progid="AxSms.Http" id="objHttp"></object>
<object runat="server" progid="AxSms.Constants" id="objSmsConstants"></object>
<object runat="server" progid="AxSms.Message" id="objSmsMessage"></object>
<%
strResult = "n/a"
strLastResponse = ""
Set fso = CreateObject("Scripting.FileSystemObject")
objHttp.LogFile = fso.GetSpecialFolder(2) & "\ActiveXperts.Http.log"
'Windows default: "C:\Windows\Temp\ActiveXperts.Http.log"
If(Request("btnSendMessage") <> "") Then
objSmsMessage.Clear()
objSmsMessage.Body = Request("txtBody")
objSmsMessage.ToAddress = Request("txtToAddress")
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT
objHttp.Clear()
objHttp.Url = Request("txtUrl")
Set obj = objSmsMessage
objHttp.SendSms obj, objSmsConstants.MULTIPART_OK
strResult = objHttp.LastError & ": " & objHttp.GetErrorDescription(objHttp.LastError)
strLastResponse = objHttp.LastResponseCode
End If
%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ActiveXperts SMS Component Demo</title>
</head>
<body>
<div class="ax_maincontainer">
<div class="ax_header">
<div class="ax_stroke"></div>
<div class="ax_logo"></div>
</div><!-- /header -->
<div class="ax_container">
<h1>SMS Component ASP HTTP Sample</h1>
<hr />
<p>
The HTTP protocol is used for medium volume SMS messaging. Messages are first routed to
the service provider via Internet/VPN. The provider delivers the messages to the
recipient's phone. If you are not subscribed to a provider, use the ActiveXperts gateway
to send 10 SMS messages for free.
</p>
<form action="http.asp" method="post">
<h2>SMS Component:</h2>
<h3>Build: <% = objHttp.Build %>; Module: <% = objHttp.Module %></h3>
<!-- Connection URL -->
<label for="Url">Connection URL:</label>
<%
strInfo = "post.activexperts-labs.com:8080/sendsms/default.asp" & _
"?username=" & "myAccount" & _
"&password=" & "myPassword" & _
"&text=" & objSmsConstants.HTTP_PLACEHOLDER_BODY & _
"&to=" & objSmsConstants.HTTP_PLACEHOLDER_TOADDRESS
%>
<p>
<input type="text" id="Url" name="txtUrl"class="ax_FullWidth"
value="<% = strInfo %>" />
</p>
<label for="ToAddress">ToAddress:</label>
<p>
<input type="text" id="ToAddress" name="txtToAddress" value="[ToAddress]" />
<a href="http://www.activexperts.com/support/sms-component/?kb=Q4200015"
target="_blank">Recipient number format</a>
</p>
<label for="Body">Body:</label>
<p>
<textarea id="Body" name="txtBody" style="height:55px;">
Hello world send from ActiveXperts SMS Component!
</textarea>
</p>
<div class="ax_clearLabel"></div>
<p>
<input type="submit" name="btnSendMessage" value="Send SMS Message!" />
</p>
<label for="Result"><b>Result:</b></label>
<p>
<input type="text" id="Result" name="txtResult"
class="ax_FullWidth Bold" value="<% = strResult %>" />
</p>
<label for="Response">Last Response:</label>
<p>
<input type="text" id="Response" name="txtLastResponse"
class="ax_FullWidth" value="<% = strLastResponse %>" />
</p>
</form>
</div><!-- /container -->
</div><!-- /maincontainer -->
</body>
</html>
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.
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.