Sending SMS using ASP through HTTP
Download source code
send-sms-through-asp-sms-hhtp-api.zip (1kB)Introduction
This article is about sending SMS using ASP through HTTP. It is intended for web developers with a basic knowledge of the ASP.NET technology. The reader should be familiar with Microsoft Visual Studio and the C# programming language. The page contains a downloadable source code (see above), a list of aims you can achieve using the code, a list of prerequisites, a description and depiction of the architecture and operation of the system, step-by-step instructions about how to use the code and a detailed interpretation. It also includes a brief summary, answers to frequently asked questions, as well as links to related information.
When to use this code
This code is particularly useful for those who wish to
- add SMS functionality to a website.
- add SMS functionality to a corporate Intranet.
- create automated SMS notifications.
- increase website security by adding SMS login.
Prerequisites
The following table lists the software requirements of the system. Note that you can download Ozeki NG - SMS Gateway and .NET Framework 4.0 on the download page.
Operating system: | Windows 2019, Windows 2016, Windows 2012 R2, Windows 8, Windows 10 or Windows 11 |
Other software requirements: |
Internet Information Services (IIS)
Ozeki NG-SMS gateway |
Development platform: | A simple word processor will do. |
How it works
To send SMS messages from ASP applications, you need to install Ozeki NG SMS Gateway on your computer. Ozeki NG - SMS Gateway will use a GSM phone/modem attached to your PC (with a phone-to-PC data cable) or an IP SMS connection to send messages. Your ASP.NET application will perform an HTTP request to send messages using the Ozeki NG program. For a better understanding of how it works, please look at the following diagram (Figure 1).
In the diagram you can see an Internet user, a web server with the ASP application, Ozeki NG - SMS Gateway, a mobile phone attached to the server computer and mobile user receiving the message. Wherever the Internet user is, if they know the IP address or URL of the computer running the ASP script, and if they are authorized to log in, they can compose and send messages to any recipients. After the Internet user's action, the ASP application initiates the process by posting an SMS message to the built-in web server of Ozeki NG - SMS Gateway. Ozeki NG will forward the message to the GSM network through a mobile phone attached to the PC using a data cable, and the mobile user will receive the SMS message.
Using the code
To use the downloaded ASP code, follow these steps:
Step 1: | Unpack the downloaded zip file. |
Step 2: | Copy the smssend.asp file into the "C:\Inetpub\wwwroot\" directory (the main directory of the IIS Server). Picture help |
Step 3: | Set/Change the fixed data in the smssend.asp file (e.g., ozSURL, ozSPort, ozUser, ozPassw). Picture help |
Step 4: | Start the Ozeki NG - SMS Gateway Server (if not running). Picture help |
Step 5: | Start a web browser application (IE, Firefox, etc.) and enter this: http://127.0.0.1/smssend.asp (127.0.0.1 means that the smssend.asp file resides on the same computer on which the browser has been opened). Picture help |
Step 6: | Fill in the necessary fields, and then then click the "Send" button. Picture help |
Step 7: | Verify the message being sent in the Ozeki NG - SMS Gateway Server. Picture help |
Understanding the code
The downloadable sample script tells Ozeki NG - SMS Gateway Server to send an SMS message to the given phone number with the given content. Inside the script you have to set the URL of the Ozeki NG Server with the port number, the username (specifying who can log in to the Ozeki NG Server) with the password and the type of the SMS message.
The source code of the example application is structured in the following way:
smssend.asp:This file contains page builder ASP elements (text boxes, etc.) and the processing script.
Description of the process depicted in Figure 1 above:
Step 1: Create the HTML form
In the smssend.asp we create the form that requests the sms data. The Internet user fills in the necessaries. Label and textbox pairs will be displayed. Labels identify the requested data for the Internet user, and they will type it in textboxes. The user will be asked to fill in the Recipient and Message Text fields. An iframe html tag is used to inform the user about the sending request. At first, it will be invisible.
smssend.asp
......
Step 2: Processing data coming from the HTML form
In "Processing script text" you check the value of the recipient field. If it is empty, an error message will be displayed. Otherwise you create the request from fixed and given data, and send it to Ozeki NG - SMS Gateway Server. The answer is shown in an iframe.
After filling in the fields and clicking on button Send, ASP server gets the information about the form. At the begining of processing the text you check the data of the textbox fields. The recipient box is mandatory. If it is empty the processing will be aborted and the Internet user will be shown the error. If the checking is successful, you will create the URL that will tell the Ozeki NG - SMS Gateway Server the requested information. You need the following:
the URL of the computer running Ozeki NG - SMS Gateway Server the default URL is http://127.0.0.1/httpapi (127.0.0.1 means that Ozeki NG - SMS Gateway Server is installed on the same computer on which the ASP script is running), the port number on which the server listens, the username, which is authorized to log in to the Ozeki NG - SMS Gateway Server and to send messages (the default username is admin), the user's password (the default is abc123), the message type (the default is SMS:TEXT), the recipient and the message data. The following values must be URL-encoded: username, password, recipient and message data.smssend.asp
... <form method="post" action=""> <table align="center"> ... <tr> <td colspan="2" align="center"> <% if Request.form("recipient") = "" then response.write("<font color='red'>Recipient 'field mustn't be empty!</font>") else dim createdURL createdURL = "" 'It will be the entire URL that we 'send to Ozeki NG SMS Gateway Server dim ozSURL ozSURL = "http://127.0.0.1" 'URL of that machine 'on where Ozeki NG SMS Gateway Server is running dim ozSPort ozSPort = "9501" 'Port number on which Ozeki NG SMS 'Gateway Server is listening to dim ozUser ozUser = server.URLEncode("admin") 'User name of that user 'who can login to Ozeki NG SMS Gateway Server dim ozPassw ozPassw = server.URLEncode("abc123") 'Password of user above dim ozMessageType ozMessageType = "SMS:TEXT" 'Type of message that we want to send dim ozRecipient ozRecipient = server.URLEncode(Request.form("recipient")) 'Recipient of 'the message dim ozMessageText ozMessageData = server.URLEncode(Request.form("messagetext")) 'Message text we want to send createdURL = ozSURL & ":" & ozSPort & "/httpapi?action=sendMessage" & "&username=" & ozUser & "&password=" & ozPassw & "&messageType=" & ozMessageType & "&recipient=" & ozRecipient & "&messageData=" & ozMessageData response.Write("<iframe src=" & createdURL & " width='500'>") end if %> </td> </tr> </table> </form> ...
Summary
In the article it has been explained how you can add SMS functionality to your website by using the downloadable ASP example code. You can freely use and modify that script. Using ASP.NET scripts (and the Ozeki NG - SMS Gateway Server) you can create a lot of useful services(e.g.: you can add SMS functionality to a website or a corporate Intranet, create automated SMS notifications, increase website security by adding SMS login, etc.).
Frequently asked questions
Question: How can I send the same message to different phone numbers?Answer: Separate the phone numbers with the comma character(,).
For example:
action can be: signal-high, signal-medium, signal-low, signal-none, signal-delete
Question: Can I run the ASP script on a computer different from the one running the Ozeki NG - SMS Gateway Server?
Answer: Yes, you can. In the script you have to set the URL and the port number of the computer running the Ozeki NG - SMS Gateway Server.
Question: Can I set the phone number so that the recipient can see where the sms comes from?
Answer: Yes, you can. In the script you have to set an originator field and include it in the URL string you have created. It works only if you have IP SMS connection.
... <form method="post" action=""> <table align="center"> ... <tr> <td colspan="2" align="center"> <% if Request.form("recipient") = "" then response.write("<font color='red'>Recipient field mustn't be empty!</font>") else dim createdURL createdURL = "" 'It will be the entire URL that we 'send to Ozeki NG SMS Gateway Server dim ozSURL ozSURL = "http://127.0.0.1" 'URL of that machine 'on where Ozeki NG SMS Gateway Server is running dim ozSPort ozSPort = "9501" 'Port number on which Ozeki NG SMS 'Gateway Server is listening to dim ozUser ozUser = server.URLEncode("admin") 'User name of that user 'who can login to Ozeki NG SMS Gateway Server dim ozPassw ozPassw = server.URLEncode("abc123") 'Password of user above dim ozOriginator ozOriginator = server.URLEncode("+449998887") 'originator of the message dim ozMessageType ozMessageType = "SMS:TEXT" 'Type of message that we want to send dim ozRecipient ozRecipient = server.URLEncode(Request.form("recipient")) 'Recipient of 'the message dim ozMessageText ozMessageData = server.URLEncode(Request.form("messagetext")) 'Message text we want to send createdURL = ozSURL & ":" & ozSPort & "/httpapi?action=sendMessage" & "&username=" & ozUser & "&password=" & ozPassw & "&messageType=" & "&originator=" & ozOriginator & ozMessageType & "&recipient=" & ozRecipient & "&messageData=" & ozMessageData response.Write("<iframe src=" & createdURL & " width='500'>") end if %> </td> </tr> </table> </form> ...
More information
- ASP SMS SDK Example 1
- ASP SMS SDK Example 2
- ASP SMS SDK Example 3
- ASP SMS SDK Example 4
- IIS Installing
- C# SMS API (using HTTP)
- C# SMS API (using SQL)
- ASP with built-in webserver C#
- SQL SMS API
- HTTP SMS API
- C Sharp SMS API
- C Sharp SMS Gateway
- Feature list of the Ozeki NG SMS Gateway
- FAQ of the Ozeki NG SMS Gateway