This sample demonstrates how to remotely send a message to a group of contacts. This can be useful when you need to send bulk SMS from a remote location (e.g. from your mobile phone or via email).
File ForwardMessage.vbs used in this sample is located in the folder:
C:\Program Files\CodeSegment\SMS Studio\Samples\InfoService
This script receives the pipe name, the text of the message, the ID of the account from which the messages should be sent and the sender address. The first word of the message text (separated with a space character from the rest of the text) should be the name of the group of recipients or the phone number of the single recipient. For example, a message text may contain [Friends] Hello there!, assuming that you have a group named Friends in the Address Book.
How to run this sample
Source code
The contents of the ForwardMessage.vbs file:
'-------------------------------------------------------------------------------------------------------------------------------
' This script demonstrates how to forward a message using Info Service Named Pipe
' After this script is executed forwarded messages will appear in the Outbox window.
' WARNING: Error checking omitted for clarity.
'
' Use the following application parameters in the Info Rule dialog:
' "%PipeName%" "%MsgText%" "ACCOUNT_ID" "SENDER_ADDRESS"
' The ACCOUNT_ID parameter should be taken (Copy&Paste) from the Edit Connection dialog / Account tab / AccountID field
'-------------------------------------------------------------------------------------------------------------------------------
if WScript.Arguments.Count = 4 then
' Collect arguments
PipeName = WScript.Arguments(0) ' Pipe name
MsgText = Trim(WScript.Arguments(1)) ' Message text
AccountID = WScript.Arguments(2) ' The ID of the account from which messages should be sent
Sender = WScript.Arguments(3) ' Sender address
if PipeName <> "" then ' Pipe name must be specified in the Info Setup dialog
Pos = InStr(MsgText," ")
if Pos > 0 then ' Message must contain recipient
Recipient = Left(MsgText,Pos-1)
MsgText = Mid(MsgText,Pos)
'Encode special characters
MsgText = Replace(MsgText,"%","%25")
MsgText = Replace(MsgText,"+","%2B")
MsgText = Replace(MsgText,vbCr,"%0D")
MsgText = Replace(MsgText,vbLf,"%0A")
' Open the pipe instance
set fso=CreateObject("Scripting.FileSystemObject")
set pipe=fso.CreateTextFile("\\.\pipe\" & PipeName)
' Forward the message
pipe.WriteLine("AccountID:" & AccountID)
pipe.WriteLine("From:" & Sender)
pipe.WriteLine("To:" & Recipient)
pipe.WriteLine("Encoded:" & MsgText)
pipe.WriteLine("<Send>") ' Send the message
pipe.Close
WScript.Quit(0) ' Success
else
WScript.Quit(1) ' Error
end if
else
MsgBox "Error: Pipe name is missing.", vbCritical, "SMS Studio Forward Message Sample"
WScript.Quit(1) ' Error
end if
else
MsgBox "Error: Wrong number of arguments.", vbCritical, "SMS Studio Forward Message Sample"
WScript.Quit(1) ' Error
end if
'-------------------------------------------------------------------------------------------------------------------------------
' Copyright (c) 2002-2009 CodeSegment. All rights reserved. http://www.codesegment.com/
'-------------------------------------------------------------------------------------------------------------------------------
| Copyright © 2002-2010 CodeSegment. All rights reserved. |