• home
  • forum
  • my
  • kt
  • download
  • Using ASP to Send a Wireless Text Message

    Author: 2007-06-30 18:29:19 From:

     

    Even though SMS is in demand, most carriers have made it extremely difficult for developers to tap into its resources. This conflict arises because of the variable costs tied to each message. In most cases, an account with each carrier will be required in order to make an Application Programming Interface (API) via TCP/IP available. Some accepted protocols adopted by carriers include the Simple Network Paging Protocol (SNPP), the Wireless Communication Transport Protocol (WCTP), and the Short Message Peer to Peer (SMPP). These protocols fall outside the scope of this article because it is possible to send SMS using alternative modes.

    Solution 1: Send a Text-Message via SMTP

    Some carriers now expose a Simple Mail Transport Protocol (SMTP), an e-mail interface to send short text messages. Typically, the e-mail address will be the device's phone number or pager identification number, along with the carrier's special domain. For example, a phone with AT&T service will have an e-mail address of 3135551212@mobile.att.net. Users must be cautious because some carriers, such as Pacific Bell, include the number 1 before the phone number (1 is the country code according to the North American Numbering Plan) in the e-mail address for the device.

    The following example uses the DevMailer 1.0 ASP object to handle e-mail, but any SMTP object could easily replace it. (15Seconds offers more on DevMailer at http://www.15Seconds.com/component/pg002059.htm.)

    The sms.inc file is a separate code document included with this article. It includes the e-mail interface and some SMS error-checking routines:

    <%
    '##################################################
    '# Requirements: dvmailer.dll
    '##################################################
    
    '##################################################
    '# Set Global Variables
    '##################################################
    SMTP_SERVER = "mail.domain.com"
    SMTP_SERVER_PORT = 25
    
    '##################################################
    '# Function to send the SMS via email
    '#
    '# Returns True/False whether the email was sent.
    '##################################################
    Public Function SendSMS(msgToEmailAddress, msgFromEmailAddress, msgSubject, msgText)
    	
    	' Set the various lengths associated with each carrier
    	' AT&T
    	If (InStr(1, msgToEmailAddress, "mobile.att.net") > 1) Then
    		maxLength = 140
    	' Nextel
    ElseIf (InStr(1, msgToEmailAddress, "messaging.nextel.com") > 1) Then
    		maxLength = 280
    	' Sprint PCS
    ElseIf (InStr(1, msgToEmailAddress, "messaging.sprintpcs.com") > 1) Then
    		maxLength = 100
    	' Default Length
    Else
    		maxLength = 140
    	End If
    	
    ' Typically, there are at least two characters of delimiter between the from,
    	' subject, and text on the screen of the mobile device.  
            
    'We must add this into the equation in order to ensure ' the entire message gets sent to the device. msgLength = len(msgFromEmailAddress & " " & msgSubject & " " & msgText) ' This is here to make sure the message isn't longer than the device supports. If ( msgLength > maxLength) Then ' Return false SendSMS = false Else ' Create DevMailer Object Set Mailer = CreateObject("Geocel.Mailer") ' Add SMTP server Mailer.AddServer SMTP_SERVER, SMTP_SERVER_PORT ' Set From Mailer.FromAddress = msgFromEmailAddress ' Set Subject Mailer.Subject = msgSubject ' Set Content Type to Text Only Mailer.ContentType = "text/plain; charset=us-ascii" ' Set the body Mailer.Body = msgText ' Add recipient Mailer.AddRecipient msgToEmailAddress, "" ' Send It SendSMS = Mailer.Send() End If End Function %>
    The sendsms.asp will pull in this function and send off a text message.
    <!--#include virtual="/sms.inc"-->
    <%
    msgTo = "3131234567@messaging.sprintpcs.com"
    msgFrom = "joelauer@domain.com"
    msgSubject = "Hello World"
    msgText = "First text-message!!"
    
    'Attempt to send the sms
    IsSent = SendSMS(msgTo, msgFrom, msgSubject, msgText)
    
    if IsSent then
    	Response.Write("SMS successfully sent to " & msgTo)
    else
    	Response.Write("SMS not successfully sent to " & msgTo)
    end if
    %>
    
    Although this interface draws a quick and dirty solution, sending SMS via e-mail still has many hidden drawbacks, including speed, assurance, error checking, features, and consistency. By its original design, e-mail was not intended to become a quick system. As a result, most text messages that are sent through e-mail experience latency problems ranging from 1 minute to 2 hours. This estimate also assumes that an SMTP server will not go down somewhere along the path of the e-mail. E-mail will not guarantee that the recipient subscribes to text messaging with their phone's normal service plan.

    Furthermore, SMS lengths range from 80 to 256 characters. Messages delivered via SMTP will normally omit those parts of the message that carry over the maximum character length. Unfortunately, your code will never discover the discarded parts of your message. The most prominent drawback is the diversity of e-mail formats between various services. In some cases, the Subject field will be used, rather than the Body field. In either case, your code will have to account for this error or else parts of your message will not reach the mobile device. An additional problem with using the e-mail format arises when the From field has already used up 20 to 30 characters in the small, allotted space of 80 to 256. Finally, SMTP does not make available many of the best features specifically available with SMS, such as one-touch callback and presence information (e.g. phone on/off, signal strength).

    Solution 2: Send a Text-Message via a Third Party

    Summary

    Third-party solutions or shrink-wrapped ASP objects provide a simple and easy way to interface to SMS devices. However, most solutions will have licensing and usage fees, since carriers set their final prices. Although SMTP will provide a low-priority path to a set amount of wireless devices, the number of devices supporting e-mail world wide is considerably small. Additionally, there are several masked complications associated with SMTP-delivered text messages. If performance, reliability, and scalability are of utmost importance, then seeking a third-party component may be the best solution for text messaging.

    There are SMS alternatives to SMTP. Third-party solutions include shrink-wrapped software and application service provider (ASP) gateways. Many third-party ASPs even provide a shrink-wrapped ASP object that will hide the TCP/IP intricacies of interfacing to their gateway. The Simplewire SMS object is one such example. The code below from swsms.asp demonstrates its easy use.

    <%
    '##################################################
    '# Requirements: swsms.dll
    '##################################################
    
    ' Create the SMS object
    Set sms = Server.CreateObject("SimplewireSMS.SMSRequest")
    
    ' Set request to message send
    sms.setSendPage
    
    ' Set properties
    sms.setSynch(True)
    sms.msgFrom = "Joe"
    sms.msgPin = "3135551212"
    sms.msgCallbackNum = "3131234567"
    sms.msgText = "Hello world with SMS!"
    
    ' Send request
    Set smsResponse = sms.send
    
    ' Error checking
    If smsResponse.isSuccess = False Then
    	Response.Write("SMS was not successfully sent. ")
    	Response.Write("Error Code: " & smsResponse.errorCode & " - " & smsResponse.errorDesc)
    Else
    	Response.Write("SMS was successfully sent.")
    End If
    
    ' Cleanup
    Set req = Nothing
    Set res = Nothing
    %>
    

    discuss this topic to forum

    relation tutorial

    No relevant information

    New

    Hot