You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > GSM/GPRS (MM1) > 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 MMS using MMS Toolkit.
Create a new Powershell file called DEMO.PS1.
Create the MMS objects like this:
$objConnection = new-object -comobject ActiveXperts.MmsProtocolMm1 $objMessage = new-object -comobject ActiveXperts.MmsMessage $objSlide = new-object -comobject ActiveXperts.MmsSlide $objConstants = new-object -comobject ActiveXperts.MmsConstants
You can now send MMS messages.
The following Powershell code shows how to send a MMS message using a GSM/GPRS or UMTS phone or modem:
################################################################################# # 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 an MMS message through a connected GPRS/UMTS modem. # # Note: # # The GPRS/UMTS phone or modem must be connected to your PC # using an USB or serial datacable, IR or BlueTooth. # ################################################################################# cls ################################################################################# # Functions --------------------------------------------------------------------# ################################################################################# ################################################################################# # 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 } ################################################################################# # AskDevice --------------------------------------------------------------------# function AskDevice($objDevice) { $n = $objDevice.GetDeviceCount() if($n -eq 0) { return "" Exit Function } $strMessage = "*** Enter one of the following device names *** `n" for($i = 0; $i -lt $n;$i++) { $strMessage = $strMessage + $objDevice.GetDevice($i) $strMessage = $strMessage + "`n" } if($n -gt 0) { $strDefaultDevice = $objDevice.GetDevice(0) } else { $strDefaultDevice = "" } do { $strDevice = Read-Host $strMessage "Input" $strDefaultDevice } until($strDevice -ne "") return $strDevice } ################################################################################# # THE SCRIPT ITSELF ------------------------------------------------------------# ################################################################################# # Create $objects $objConnection = new-object -comobject ActiveXperts.MmsProtocolMm1 $objMessage = new-object -comobject ActiveXperts.MmsMessage $objSlide = new-object -comobject ActiveXperts.MmsSlide $objConstants = new-object -comobject ActiveXperts.MmsConstants # Device $objConnection.Device = AskDevice($objConnection) if($objConnection.Device -eq "") { Write-Host "No TAPI devices available" Write-Host "Ready." Start-Sleep -m 3000 exit } # LogFile $objConnection.LogFile = "MmsLog.txt" # provider properties GPRS APN, WAP Gateway and MMSC Server Address. # Please check http://www.activexperts.com/mmstoolkit/mmsclist, or ask your provider for # your provider#s settings # APN $objConnection.ProviderAPN = ReadInput "Enter the providers Access Point Name (APN)" "MMS" 0 # APN Account $objConnection.ProviderAPNAccount = ReadInput "Enter the accountname associated with the APN (optional)" "" 1 # APN Password $objConnection.ProviderAPNPassword = ReadInput "Enter the password associated with the APN (optional)" "" 1 # WAP Gateway $objConnection.ProviderWAPGateway = ReadInput "Enter the IP address of the WAP Gateway/Proxy" "10.250.255.183" 0 # MMSC URL $objConnection.ProviderMMSC = ReadInput "Enter the URL of the provider#s MMSC" "http://mms.orange.nl:8002/" 0 # MMSlide: Add duration, attachments(s) and text(s) - Display this screen for 10 seconds $objSlide.Duration = 10 $objSlide.AddAttachment("logo.gif") $objSlide.AddText("The ActiveXperts logo") # Clear Message $objMessage.Clear() # Message Subject $objMessage.Subject = "MMS Message" # Message Recipient $recipient = ReadInput "Enter recipient address" "+" 0 $objMessage.AddRecipient($recipient, $objConstants.asMMS_RECIPIENT_TO) # advanced message properties $objMessage.Class = $objConstants.asMMS_CLASS_PERSONAL $objMessage.Priority = $objConstants.asMMS_PRIORITY_HIGH # Add the slide created above. Note:You can add multiple slides $objMessage.AddSlide($objSlide) # GPRS/UMTS: connect now Write-Host "Connecting..." $objConnection.Connect() Write-Host "Connect, result: " $objConnection.LastError " (" $objConnection.GetErrorDescription($objConnection.LastError) ")" if($objConnection.LastError -ne 0 ) { Start-Sleep -m 3000 exit } # Send the message Write-Host "Sending message..." $objConnection.Send($objMessage) Write-Host "Send, result: " $objConnection.LastError " (" ` $objConnection.GetErrorDescription($objConnection.LastError) ` "Provider response: " $objConnection.ProviderResponse ` "MessageID: " $objConnection.MessageId # GPRS/UMTS Disconnect $objConnection.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.