ActiveXperts SMS and MMS Toolkit Add SMS and MMS capabilities to any Windows or .NET application

Using The SMS and MMS Toolkit with VBScript

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:

  • Send and receive numeric- and alphanumeric text SMS messages
  • Verify delivery of outgoing SMS messages
  • Support for multimedia SMS messages, including ringtones, pictures and logo's
  • Support for WAP Push, WAP Bookmarks, vCards, voicemail/e-mail/fax/MMS indications
  • Support for Unicode, to support foreign languages like Arabic, Chinese, Hebrew, etc.
  • Support for multi-part messages, to allow messages longer than 160 characters
  • Support for GSM modems, GSM phones, SMS/HTTP providers, SMPP (Short Message Peer to Peer) providers, TAP/XIO and UCP dial-in SMSC providers
  • Support Multi-threading environments. The component is thread-safe, which means it can be used in a multi-threaded environment
  • Samples included for various development platforms: MS Visual Basic, MS Visual Basic .NET, MS Visual C++, MS Visual Studio C# .NET, ASP, ASP .NET, Borland Delphi, Borland C++ Builder, Windows Powershell ColdFusion and more

MMS features:

  • Support for many multimedia formats incl.: JPG, GIF, PNG, BMP, WBMP, TIF, WAV, MP3, MIDI, AC3, GP3, AVI, MPG, MP4, VCARD, VCALENDAR, JAR and more
  • Support for MM1 (MMS over WAP), MM4 (MMS over SMTP) and MM7 (MMS over HTML/SOAP)

Pager features:

  • Send alpha-numeric Pager messages through SNPP

This document describes how the SMS and MMS Toolkit can be integrated into VBScript projects.

Step 1: Download and install The SMS and MMS Toolkit

Download the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

You're now able to write a more advanced VBScript script to send/receive SMS using SMS and MMS Toolkit.

Step 3: Create the SMS and MMS Toolkit objects in VBScript

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:

Option Explicit

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.

Insert the following line to declare and create the GSM object:

Set objGsmProtocol  = CreateObject( "ActiveXperts.SmsProtocolGsm" )

Insert the following line to declare and create the SmsMessage object:

Set objSmsMessage  = CreateObject( "ActiveXperts.SmsMessage" )

Insert the following line to declare and create the SmsConstants object:

Set objSmsConstants  = CreateObject( "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 " $objGsmProtocol.Version " demo."
Write-Host "Expiration date: " $objGsmProtocol.ExpirationDate

Step 4: Send and/or receive SMS messages

You can now send and/or receive SMS messages.

The following Powershell code shows how to send a SMS message using a connected GSM 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 raw 8 bit data using SMS (max 140 bytes).
#
# Note:
#    The GSM phone or modem must be connected to your PC
#    using an USB or serial datacable, IR or BlueTooth.
#
#################################################################################

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)
	}

#################################################################################
# AskDevice --------------------------------------------------------------------#

function AskDevice($objDevice)
	{
		$n              = $objDevice.GetDeviceCount()
		$strMessage     = "*** Enter one of the following device names *** `n"
		for($i=0;$i -lt $n;$i++)
			{
				$strMessage = $strMessage + $objDevice.GetDevice($i)
				$strMessage = $strMessage + "`n"
			}	
		$strMessage = $strMessage + "COM1`n" + "COM2`n" + "COM3`n" + "COM4`n"

		if( $n -gt 0 )
			{
				$strDefaultDevice = $objDevice.GetDevice( 0 )
			}	
		else
			{
				$strDefaultDevice = "COM1"
			}	
		
		do
			{
				$strDevice = Read-Host($strMessage,"Input")
			}	
		until($strDevice -ne "")

		return $strDevice
	}
		

#################################################################################
# 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
$objGsmProtocol          = new-object -comobject ActiveXperts.SmsProtocolGsm
$objSmsMessage           = new-object -comobject ActiveXperts.SmsMessage
$objConstants            = new-object -comobject ActiveXperts.SmsConstants

Write-Host "ActiveXperts SMS and MMS Toolkit " $objGsmProtocol.Version " demo."
Write-Host "Expiration date: " $objGsmProtocol.ExpirationDate

# Set LogFile
$objGsmProtocol.LogFile              = "c:\SmsGsmLog.txt"

# Select Device
$objGsmProtocol.Device               = AskDevice($objGsmProtocol)

# Enter PinCode (optional)
$strPin                      = ReadInput "Enter PIN code (leave blank for no PIN code)" "1234" 1 
if($strPin -ne "")
	{
		Write-Host "Submitting PIN code; please wait..."
		$objGsmProtocol.EnterPin( $strPin )
		Write-Host "EnterPin, result: " $objGsmProtocol.LastError " (" $objGsmProtocol.GetErrorDescription( $objGsmProtocol.LastError ) ")"
		if($objGsmProtocol.LastError -ne 0)
			{
				exit
			}	
	}
	
# Message: set all properties
$objSmsMessage.Clear()
$objSmsMessage.Recipient        = ReadInput "Enter Recipient" "+316123344556" 0
$objSmsMessage.Format           = $objConstants.asMESSAGEFORMAT_DATA
$objSmsMessage.Data             = "0102030405060708090A0B0C0D0E0F"

# Use GSM provider's validity period (To be specified in minutes)
$objSmsMessage.ValidityPeriod   = 0                          

$rc = Show-Msgbox -message "Do you want a delivery report after submitting the message (please note: it can take minutes or even hours before a delivery report is received)?" -icon "exclamation" -button "YesNo" -title "Hey $env:username!!"

if($rc -eq "Yes" )
	{
		$objSmsMessage.RequestDeliveryStatus = $true
	}	
else
	{
		$objSmsMessage.RequestDeliveryStatus = $false
	}	

# Send the message 
Write-Host "Sending the message..."
$strReference               = $objGsmProtocol.Send($objSmsMessage)	
Write-Host "Send, result: " $objGsmProtocol.LastError " (" $objGsmProtocol.GetErrorDescription( $objGsmProtocol.LastError ) ")"
if($objGsmProtocol.LastError -ne 0)
	{
		Start-Sleep -m 3000
		exit
	}
	
# Show the Message Reference
Write-Host "Message Reference (can be used with status reports): " $strReference

# Check delivery - if it was selected before
if($objSmsMessage.RequestDeliveryStatus -ne $true)
	{
		Write-Host "The program will now check for a delivery report every 5 seconds."
		$bContinueQueryStatus = $true
		while($bContinueQueryStatus)
			{
				$objDeliveryStatus = $objGsmProtocol.QueryStatus($strReference)
				Start-Sleep -m 3000
				if($objGsmProtocol.LastError -ne 0)
					{
						Write-Host "Failed to query status, error: " $objGsmProtocol.LastError
						$bContinueQueryStatus = $false
					}	
				else
					{
						Write-Host "QueryStatus for message #" $strReference ", status: " $objDeliveryStatus.Status " ("  $objDeliveryStatus.StatusDescription ")"
						if($objDeliveryStatus.IsCompleted)
							{
								Write-Host "Completed, Final Status=" $objDeliveryStatus.Status " ("  $objDeliveryStatus.StatusDescription ")"
								Write-Host "StatusCode=" $objDeliveryStatus.StatusCode "; StatusTime=" $objDeliveryStatus.StatusCompletedTime
								$bContinueQueryStatus = $false
							}
					}	
			}	
	}	

Write-Host "Ready."
Start-Sleep -m 3000

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.