You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > GSM/GPRS (MM1) > VBScript
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 VBScript 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 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 MMS using MMS Toolkit.
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.
Now, declare the SMS and MMS Toolkit objects:
Dim objMm1Protocol Dim objMmsMessage Dim objMmsConstants Dim objMmsSlide
Create the MMS objects like this:
Set objMm1Protocol = CreateObject( "ActiveXperts.MmsProtocolMm1" ) Set objMmsMessage = CreateObject( "ActiveXperts.MmsMessage" ) Set objMmsConstants = CreateObject( "ActiveXperts.MmsConstants" ) Set objMmsSlide = CreateObject( "ActiveXperts.MmsSlide" )
Now, add the following lines to the file to have your fist SMS and MMS Toolkit VBScript program:
WScript.Echo "Version: " & objMm1Protocol.Version WScript.Echo "Expiration Date: " & objMm1Protocol.ExpirationDate
You can now receive MMS messages.
The following VBScript code shows how to receive MMS messages using a GSM/GPRS or UMTS phone or modem:
Option Explicit
' Declare objects
Dim objConstants, objMessage, objConnection, objSlide
' Declare variables
Dim n, nCount
Dim m, nAttachments
' Create objects
Set objConnection = CreateObject ( "ActiveXperts.MmsProtocolMm1" )
Set objConstants = CreateObject ( "ActiveXperts.MmsConstants" )
' Set 'Device'
objConnection.Device = AskDevice( objConnection )
If( objConnection.Device = "" ) Then
WScript.Echo "No TAPI devices available"
WScript.Echo "Ready."
WScript.Sleep 3000
WScript.Quit
End If
' Set 'LogFile'
objConnection.LogFile = "c:\MmsLog.txt"
' Set 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
' Set APN
objConnection.ProviderAPN = ReadInput ( "Enter the providers Access Point Name (APN)", "portalmmm.nl", False )
' Set APN Account
objConnection.ProviderAPNAccount = ReadInput ( "Enter the accountname associated with the APN (optional)", "", True )
' Set APN Password
objConnection.ProviderAPNPassword = ReadInput ( "Enter the password associated with the APN (optional)", "", True )
' Set WAP Gateway
objConnection.ProviderWAPGateway = ReadInput ( "Enter the IP address of the WAP Gateway/Proxy", "10.10.100.20", False )
' Set MMSC URL
objConnection.ProviderMMSC = ReadInput ( "Enter the URL of the provider's MMSC", "http://mp.mobiel.kpn/mmsc", False )
' Download MMS notifications from SIM card
nCount = objConnection.CountReceivedMessages
WScript.Echo "CountReceivedMessages, result: " & objConnection.LastError & " (" & _
objConnection.GetErrorDescription ( objConnection.LastError ) & ")"
If ( objConnection.LastError <> 0 ) Then
WScript.Quit
End If
If ( nCount = 0 ) Then
WScript.Echo "No new messages waiting..."
WScript.Sleep 3000
WScript.Quit
End If
' GPRS/UMTS: connect now
WScript.Echo "Connecting..."
objConnection.Connect
WScript.Echo "Connect, result: " & objConnection.LastError & " (" & _
objConnection.GetErrorDescription ( objConnection.LastError ) & ")"
If ( objConnection.LastError <> 0 ) Then
WScript.Sleep 3000
WScript.Quit
End If
For n = 0 To nCount - 1
On Error Resume Next
Set objMessage = objConnection.GetMessage ( n )
On Error Goto 0
WScript.Echo "Get message, result: " & objConnection.LastError & " (" & _
objConnection.GetErrorDescription ( objConnection.LastError ) & ")"
If ( objConnection.LastError = 0 ) Then
WScript.Echo "New MMS message received from: " & objMessage.From
On Error Resume Next
Set objSlide = objMessage.GetFirstSlide ()
On Error Goto 0
While ( objMessage.LastError = 0 )
nAttachments = objSlide.CountAttachments ()
For m = 0 To nAttachments - 1
WScript.Echo "Attachment found: " & objSlide.GetAttachmentName ( m )
objSlide.SaveAttachment m, "c:\temp\" & objSlide.GetAttachmentName ( m )
Next
On Error Resume Next
Set objSlide = objMessage.GetNextSlide ()
On Error Goto 0
WEnd
End If
Next
' GPRS/UMTS Disconnect
objConnection.Disconnect
WScript.Echo "Disconnected."
WScript.Echo "Ready."
WScript.Sleep 3000
' ***************************************************************************
' Function AskDevice
' ***************************************************************************
Function AskDevice( objDevice )
Dim strMessage, strDevice, strDefaultDevice, i, n
n = objDevice.GetDeviceCount()
If( n = 0 ) Then
AskDevice = ""
Exit Function
End If
strMessage = "*** Enter one of the following device names *** " & vbCrLf & vbCrLf
For i = 0 To n - 1
strMessage = strMessage & objDevice.GetDevice( i )
strMessage = strMessage & vbCrLf
Next
If( n > 0 ) Then
strDefaultDevice = objDevice.GetDevice( 0 )
Else
strDefaultDevice = ""
End If
Do
strDevice = InputBox( strMessage, "Input", strDefaultDevice )
Loop until strDevice <> ""
AskDevice = strDevice
End Function
' ***************************************************************************
' Function ReadInput
' ***************************************************************************
Function ReadInput( ByVal strTitle, ByVal strDefault, ByVal bAllowEmpty )
Dim strInput, strReturn
Do
strInput = inputbox( strTitle, "Enter value", strDefault )
If ( strInput <> "" ) Then
strReturn = strInput
End If
Loop until strReturn <> "" Or bAllowEmpty
ReadInput = strReturn
End Function
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.