You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use MMS Toolkit > SMTP (MM4) > 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.MmsProtocolMm4 $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 SMTP:
################################################################################# # 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 SMTP connection (MM4). ################################################################################# 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 } ################################################################################# # THE SCRIPT ITSELF ------------------------------------------------------------# ################################################################################# # Create $objects $objConnection = new-object -comobject ActiveXperts.MmsProtocolMm4 $objMessage = new-object -comobject ActiveXperts.MmsMessage $objSlide = new-object -comobject ActiveXperts.MmsSlide $objConstants = new-object -comobject ActiveXperts.MmsConstants # Logfile $objConnection.LogFile = "mm4log.txt" # Mmslide: Add duration, attachments(s) and text(s) $objSlide.Clear() #Display this screen for 10 seconds $objSlide.Duration = 10 $objSlide.AddAttachment("logo.gif") $objSlide.AddText("The ActiveXperts logo") # Subject $objMessage.Subject = "MMS Message" # Recipient $recipient = ReadInput "Enter recipient address" "+" 0 $objMessage.AddRecipient($recipient, $objConstants.asMMS_RECIPIENT_TO) # MessageClass $objMessage.Class = $objConstants.asMMS_CLASS_PERSONAL # Message Priority $objMessage.Priority = $objConstants.asMMS_PRIORITY_HIGH # MmsMessage: Add the slide created above. Note:You can add multiple slides $objMessage.AddSlide($objSlide) # Connection: Provider properties $objConnection.ProviderHost = "192.168.31.99" $objConnection.ProviderPort = 25 $objConnection.ProviderAccount = "mm4" $objConnection.ProviderPassword = "secret" $objConnection.ProviderDomain = "activexperts.dom" $objConnection.ProviderMM4Version = $objConstants.asMMS_VERSION_5_2_0 # Send the message $objConnection.Send($objMessage) Write-Host "Send, result: " $objConnection.LastError " (" $objConnection.GetErrorDescription($objConnection.LastError)")" 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.