You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > SMPP Provider > 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.
Create the objects like this:
$objSmpp = new-object -comobject ActiveXperts.SmsProtocolSmpp $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 Powershell program:
Write-Host "ActiveXperts SMS and MMS Toolkit " $objSmpp.Version " demo." Write-Host "Expiration date: " $objSmpp.ExpirationDate
You can now send and/or receive SMS messages.
The following Powershell code shows how to connect to a SMPP provider and send a SMS message:
################################################################################# # 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 ################################################################################# # Send a text SMS message through a SMPP provider. ################################################################################# cls ################################################################################# # Functions --------------------------------------------------------------------# ################################################################################# ################################################################################# # Show-Msgbox ------------------------------------------------------------------# function Show-Msgbox { Param([string]$message=$(Throw "You must specify a message"), [string]$button="okonly", [string]$icon="information", [string]$title="Message Box" ) # Buttons: OkOnly, OkCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel # Icons: Critical, Question, Exclamation, Information [reflection.assembly]::loadwithpartialname("microsoft.visualbasic") | Out-Null [microsoft.visualbasic.interaction]::Msgbox($message,"$button,$icon",$title) } ################################################################################# # ReadInput --------------------------------------------------------------------# function ReadInput($strTitle, $strDefault, $bAllowEmpty) { $strReturn = "" do { $strInput = Read-host($strTitle, " - Enter value (e.g.:", $strDefault, ")") if($strInput -ne "") { $strReturn = $strInput } if($bAllowEmpty -eq 1) { break } } while($strReturn -eq "") return $strReturn } ################################################################################# # THE SCRIPT ITSELF ------------------------------------------------------------# ################################################################################# # Create $objects $objSmpp = new-object -comobject ActiveXperts.SmsProtocolSmpp $objMessage = new-object -comobject ActiveXperts.SmsMessage $objConstants = new-object -comobject ActiveXperts.SmsConstants Write-Host "ActiveXperts SMS and MMS Toolkit " $objSmpp.Version " demo." Write-Host "Expiration date: " $objSmpp.ExpirationDate # Set LogFile $objSmpp.LogFile = "c:\SmsSmppLog.txt" # Set Server $objSmpp.Server = ReadInput "Enter hostname of SMPP server -" "smpp.activexperts-labs.com" 0 # Set ServerPort $objSmpp.ServerPort = ReadInput "Enter portnumber of SMPP server -" "2775" 0 # Set SystemID $objSmpp.SystemID = ReadInput "Enter account SystemID -" "AXGWACCOUNT" 0 # Set SystemPassword $objSmpp.SystemPassword = ReadInput "Enter account Password -" "CFEE0983BA" 0 # Connect to the provider $objSmpp.Connect() Write-Host "Connect, result: " $objSmpp.LastError " (" $objSmpp.GetErrorDescription($objSmpp.LastError) ")" if($objSmpp.LastError -ne 0) { Start-Sleep -m 3000 exit } Write-Host "Connected to provider" # Message: set all properties $objMessage.Clear() $objMessage.Sender = "+316121345678" $objMessage.Recipient = ReadInput "Enter Recipient - " "+" 0 $objMessage.Data = ReadInput "Enter the message text you want to send to the recipient - " "Hello ,world!" 0 # Message: if data larger than 160 characters then ask to allow multi-part # Default: single-part SMS message $objMessage.Format = $objConstants.asMESSAGEFORMAT_TEXT $objMsgdata = $objMessage.Data if($objMsgdata.length -gt 160 ) { $msg = Show-MsgBox -message "Message exceeds 160 characters. Do you want to send the SMS as a multi-part message?" -icon "exclamation" -button "YesNo" if($msg -eq "Yes" ) { $objMessage.Format = $objConstants.asMESSAGEFORMAT_TEXT_MULTIPART } } # Send the message Write-Host "Sending the message..." $strReference = $objSmpp.Send($objMessage) # Show the result Write-Host "Send, result: " $objSmpp.LastError " (" $objSmpp.GetErrorDescription($objSmpp.LastError) ")" if($objSmpp.LastError -ne 0) { $objSmpp.Disconnect() Start-Sleep -m 3000 exit } # Show the Message Reference Write-Host "Message Reference (can be used with status reports): " $strReference # Query message status until completed $objDeliveryStatus = $objSmpp.QueryStatus($strReference, $true) # When completed, show final message status if($objDeliveryStatus) { Write-Host "Final status of the message: " $objDeliveryStatus.Status " (" $objDeliveryStatus.StatusDescription ")" } $objSmpp.Disconnect() Write-Host "Disconnected." 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.