How to Send a Message from the Web through Named Pipe

This sample demonstrates how to send a message from the web.

Files used in this sample are located in the folder:

    C:\Program Files\CodeSegment\SMS Studio\Samples\InfoService\WebSend

How to run this sample

  1. Install a web server on your computer. See How to Setup a Web Server for detailed instructions.
  2. Copy the send_sms.asp and test_send_sms_asp.htm files to a folder accessible by your web server (e.g. C:\Inetpub\wwwroot\smsstudio).
  3. Click the New button on the main toolbar and select the Info service option in the New Service dialog.
  4. Click the Setup button on the main toolbar to display the Info Setup dialog.
  5. In the Advanced tab of the Info Setup dialog enter the following parameters:
    Pipe name: WebSendPipe
    Remote user: Everyone (or use IUSR_machine_name to restrict access to your web users only)
    Default sending account: Use the selection button ( ... ) to select the account to send messages with.
  6. Click the OK button to close the Info Setup dialog.
  7. Click the Start button on the main toolbar to start the Info service.
  8. To test sending on your computer, use the following link:
    http://localhost/smsstudio/test_send_sms_asp.htm.
    Fill in the fields and click the Submit button. You should see the confirmation page in your browser. Check the Outbox window in SMS Studio to see the status of the outgoing message.
  9. To test sending from a remote location, use the following link:
    http://YOUR_DOMAIN_NAME_OR_IP_ADDRESS/smsstudio/test_send_sms_asp.htm
  10. You can now inform your client to send messages by using the following syntax:
    http://YOUR_DOMAIN_NAME_OR_IP_ADDRESS/smsstudio/send_sms.asp?from=SENDER&to=RECIPIENT&msg=MESSAGE_TEXT

Source code

The contents of the send_sms.asp file:

<%
'-------------------------------------------------------------------------------------------------------------------------------
' This script demonstrates how to send a message from the web using Info Service Named Pipe.
' After this script is executed a message will appear in the Outbox window.
' WARNING: Error checking omitted for clarity.
' However, the remote computer will get the Ok response only after successful reception of a message.
'-------------------------------------------------------------------------------------------------------------------------------

AllowedIP = "127.0.0.1"                           ' Put the IP address of the remote computer allowed to send you messages
RemoteIP = Request.ServerVariables("REMOTE_ADDR") ' Take the address of the remote computer which tries to send you this message
RemoteIP = AllowedIP                              ' Delete or comment this line to enable the simple IP check

if RemoteIP = AllowedIP then
    
    MsgText =   Request("msg")
    Sender =    Request("from")
    Recipient = Request("to")
    
    PipeName = "WebSendPipe"                      ' Name of the pipe. This value must be specified in the Info Setup dialog

    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set pipe = fso.CreateTextFile("\\.\pipe\" & PipeName) ' Open the pipe instance

    pipe.WriteLine("From: " & Sender)
    pipe.WriteLine("To: " & Recipient)
    pipe.WriteLine("Body: " & MsgText)

    pipe.WriteLine("<Send>")                      ' Send the message

    pipe.Close                                    ' Close the pipe instance

    response.write("Ok")                          ' This line will not be executed in case of the failure
    
else
    
    response.write("Not allowed.")                ' Our simple IP check detected not allowed access
    
end if

'-------------------------------------------------------------------------------------------------------------------------------
' Copyright (c) 2002-2009 CodeSegment. All rights reserved.                                          http://www.codesegment.com/
'-------------------------------------------------------------------------------------------------------------------------------
%>

Related topics

Named Pipe

 

Copyright © 2002-2010 CodeSegment. All rights reserved.

   www.codesegment.com