You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > HTTP/SMS > Powershell 1.0
Quicklinks
The SMS and MMS Toolkit is a software development kit (SDK) to enhance an application or script with SMS, MMS and Pager functionality. SMS messages can be sent using a GSM/GPRS modem, an SMPP provider, an HTTP compliant SMS provider or using a standard dialup or fixed-line SMS modem. MMS messages can be sent via a GSM/GPRS modem (MM1), an SMTP server (MM4) or an XML/SOAP compliant provider (MM7).
SMS features:
MMS features:
Pager features:
This document describes how the SMS and MMS Toolkit can be integrated into Powershell projects.
Download the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Create a new script using your favorite editor. You can simply use notepad. However, a Powershell editor is recommended, so you can browse through objects, objects properties and object functions.
You're now able to write a more advanced Powershell script to send/receive SMS using SMS and MMS Toolkit.
Create a new Powershell file called DEMO.PS1.
This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.
Create the objects like this:
$objHttp = new-object -comobject ActiveXperts.SmsProtocolHttp $objMessage = new-object -comobject ActiveXperts.SmsMessage $objConstants = new-object -comobject ActiveXperts.SmsConstants
Now, add the following lines to the file to have your fist SMS and MMS Toolkit VBScript program:
Write-Host "ActiveXperts SMS and MMS Toolkit " $objHttp.Version " demo." Write-Host "Expiration date: " $objHttp.ExpirationDate "`r`n"
You can now send and/or receive SMS messages.
The following VBScript code shows how to send a SMS message using an HTTP Based SMS solution provider:
################################################################################# # ActiveXperts SMS and MMS Toolkit - Powershell script # © Copyright ActiveXperts Software B.V. # # For more information about ActiveXperts SMS and MMS Toolkit, please # visit the online ActiveXperts SMS and MMS Toolkit page at: # http://www.activexperts.com ################################################################################# # Sends an single SMS message through an SMS/HTTP connection. ################################################################################# cls ################################################################################# # Functions --------------------------------------------------------------------# ################################################################################# ################################################################################# # ReadInput --------------------------------------------------------------------# function ReadInput($strTitle, $strDefault, $bAllowEmpty) { $strReturn = "" do { $strInput = Read-host($strTitle, " - (e.g.:", $strDefault, ")") if($strInput -ne "") { $strReturn = $strInput } if($bAllowEmpty -eq 1) { break } } while($strReturn -eq "") return $strReturn } ################################################################################# # THE SCRIPT ITSELF ------------------------------------------------------------# ################################################################################# # Create $objects $objHttp = new-object -comobject ActiveXperts.SmsProtocolHttp $objMessage = new-object -comobject ActiveXperts.SmsMessage $objConstants = new-object -comobject ActiveXperts.SmsConstants Write-Host "ActiveXperts SMS and MMS Toolkit " $objHttp.Version " demo." Write-Host "Expiration date: " $objHttp.ExpirationDate "`r`n" # Set Logfile # $objHttp.LogFile = "HttpPostSms.log" # Set ProviderHost $objHttp.ProviderHost = "post.activexperts-labs.com" # Set ProviderPort $objHttp.ProviderPort = 8080 # Proxy Server Settings ( optional ) # $objHttp.ProxyServer = "192.168.31.95:8080" # $objHttp.ProviderAccount = "Administrator" # $objHttp.ProviderPassword = "secret" # Provider Response templates # Response should NOT contain 'ERR' $objHttp.ProviderErrorResponse = "ERR" # Response should contain 'id' $objHttp.ProviderSuccessResponse = "id" # URL Templates $objHttp.URLText = "/sendsms/default.asp?username=AXGWACCOUNT&password=CFEE0983BA&text=%MESSAGEDATA%&to=%MESSAGERECIPIENT%&from=%MESSAGESENDER%" $objHttp.URLBinary = "/sendsms/default.asp?username=AXGWACCOUNT&password=CFEE0983BA&text=%MESSAGEDATA%&to=%MESSAGERECIPIENT%&from=%MESSAGESENDER%&data=1" $objHttp.URLUnicode = "/sendsms/default.asp?username=AXGWACCOUNT&password=CFEE0983BA&text=%MESSAGEDATA%&to=%MESSAGERECIPIENT%&from=%MESSAGESENDER%&unicode=1" # SMS Message Properties $objMessage.Format = $objConstants.asMESSAGEFORMAT_TEXT $objMessage.Recipient = ReadInput "Enter recipient address" "+" false $objMessage.Data = ReadInput "Enter the message" "ActiveXperts SMS and MMS Toolkit HTTP Demo" false $objMessage.Sender = ReadInput "Enter sender address" "+31638740160" false $objHttp.Send($objMessage) Write-Host "Send, result: " $objHttp.LastError " (" $objHttp.GetErrorDescription($objHttp.LastError) ")" Write-Host "Response: " $objHttp.ProviderResponse Write-Host "Ready" Start-Sleep -m 3000
To run the code, start Powershell and browse to the location of the file you just created. Enter .\Demo.ps1 to run the code. Notice that if the script is not working, you have to change the execution policy; you can do that with the following command:
Set-ExecutionPolicy -unrestricted
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/mobile-messaging-component.