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

Quicklinks


Using SMS and MMS Toolkit with Visual Basic.NET (MM1 Connection)

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 Visual Basic.NET projects.

Step 1: Download and install the SMS and MMS Toolkit

Download the 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 Visual Basic .NET Project

Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):

Visual Basic .NET

(Click on the picture to enlarge)

Step 3: Refer to the SMS and MMS Toolkit Library and create the objects

Now that a new project has been created, you must add a reference to the SMS and MMS Toolkit in the project to be able to use the the SMS and MMS Toolkit objects. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveXperts SMS and MMS Toolkit Type Library' as shown in the following picture:

Visual Basic .NET

(Click on the picture to enlarge)

Click 'OK' to close the 'Add Reference' dialog.

On top of your code, type the following line to use the SMS and MMS Toolkit namespace:

Imports AXmsCtrl

In your Main function, declare and create the following objects:

Dim objMmsProtocolMm1 As MmsProtocolMm1
Dim objMmsMessage     As MmsMessage
Dim objMmsSlide       As MmsSlide
Dim objMmsConstants   As MmsConstants
      
objMmsProtocolMm1  = New MmsProtocolMm1 ()
objMmsMessage      = new MmsMessage ()
objMmsSlide        = new MmsSlide ()
objMmsConstants    = new MmsConstants ()

Step 4: Receive MMS messages

You can now receive MMS messages.

The following code shows how to receive an MMS message:


Imports AXmsCtrl

Module Module1
  Sub Main()
    Dim objMmsReceive As MmsReceive
    objMmsReceive = New MmsReceive
    objMmsReceive.GetNewMessages()
  End Sub
End Module

Public Class MmsReceive
  ' Mm1Protocol
  Dim objMm1Protocol As MmsProtocolMm1

  ' Create an instance of the SMS and MMS toolkit
  Public Sub New()
    objMm1Protocol = New MmsProtocolMm1()
  End Sub

  
  ''' <summary>
  '''    Retrieve messages from SIM
  ''' </summary>
  ''' <remarks></remarks>
  Public Sub GetNewMessages()
    ' Declare variables
    Dim objMmsMessage As MmsMessage
    Dim objMmsSlide As MmsSlide

    Dim numMessages = 0
    Dim numAttachments = 0
    Dim m = 0
    Dim n = 0

    ' Get devices
    objMm1Protocol.Device = ReadDevice()

    ' Read pin
    Dim strPin = ReadInput("Enter PIN code (leave blank for no PIN code):", True)
    If (Not String.IsNullOrEmpty(strPin)) Then
      Console.WriteLine("Submitting PIN code; please wait...")
      objMm1Protocol.EnterPin(strPin)
      Console.WriteLine("EnterPin, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")

      If (objMm1Protocol.LastError <> 0) Then
        Console.WriteLine("Ready. Press any key to exit the application.")
        Console.ReadLine()
        Exit Sub
      End If
    End If

    ' MMSC Settings
    objMm1Protocol.ProviderAPN = ReadInput("Enter APN: ", False)
    objMm1Protocol.ProviderAPNAccount = ReadInput("Enter APN Account (optional): ", True)
    objMm1Protocol.ProviderAPNPassword = ReadInput("Enter APN Password (optional): ", True)
    objMm1Protocol.ProviderWAPGateway = ReadInput("Enter WAP Gateway: ", False)
        
    ' Count new messages
    Console.WriteLine("Counting messages...")
    numMessages = objMm1Protocol.CountReceivedMessages()
    Console.WriteLine("CountReceivedMessages, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")

    If (objMm1Protocol.LastError <> 0) Then
      Console.WriteLine("Ready. Press any key to exit the application.")
      Console.ReadLine()
      Exit Sub
    End If

    Console.WriteLine("Connecting...")
    objMm1Protocol.Connect()
    Console.WriteLine("Connect, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")

    If (objMm1Protocol.LastError <> 0) Then
      Console.WriteLine("Ready. Press any key to exit the application.")
      Console.ReadLine()
      Exit Sub
    End If

    ' Loop through the messages
    For n = 0 To (numMessages - 1)
      Console.WriteLine("Retrieving message...")
      objMmsMessage = objMm1Protocol.GetMessage(n)
      Console.WriteLine("GetMessage, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")

      If (objMm1Protocol.LastError = 0) Then
        Console.WriteLine("New MMS received from: " & objMmsMessage.From)
        Console.WriteLine("Subject:               " & objMmsMessage.Subject)

        objMmsSlide = objMmsMessage.GetFirstSlide()
        While (objMm1Protocol.LastError = 0 And Not objMmsSlide Is Nothing)
          numAttachments = objMmsSlide.CountAttachments()
          
          For m = 0 To (numAttachments - 1)
            Console.WriteLine("Attachment found: " & objMmsSlide.GetAttachmentName(m))
          Next
          
          objMmsSlide = objMmsMessage.GetNextSlide()
        
        End While
      End If
    Next

    ' Disconnect
    objMm1Protocol.Disconnect()
    Console.WriteLine("Disconnected.")

    Console.WriteLine("Ready. Press any key to exit the application.")
    Console.ReadLine()
  End Sub

  
  ''' <summary>
  '''    Read prefered device
  ''' </summary>
  ''' <returns>Devicename</returns>
  ''' <remarks></remarks>
  Private Function ReadDevice()
    Dim strInput = String.Empty
    Dim intInput As Integer
    Dim strDevice = String.Empty
    Dim j As Integer

    Console.WriteLine("Select a device: ")

    For j = 0 To (objMm1Protocol.GetDeviceCount() - 1)
      Console.WriteLine("  " & j.ToString() & ": " & objMm1Protocol.GetDevice(j).ToString())
    Next

    While (String.IsNullOrEmpty(strInput))
      Console.Write("  > ")
      strInput = Console.ReadLine()

      If (Integer.TryParse(strInput, intInput) And intInput < j) Then
        strDevice = objMm1Protocol.GetDevice(System.Int32.Parse(strInput))
      End If
    End While

    Console.WriteLine("  Selected device: " & strDevice & vbLf)
    ReadDevice = strDevice
  End Function

  
  ''' <summary>
  '''    Collect user input using Console.Readline()
  ''' </summary>
  ''' <param name="strTitle">A question</param>
  ''' <param name="bAllowEmpty"></param>
  ''' <returns>The user input</returns>
  ''' <remarks></remarks>
  Private Function ReadInput(ByVal strTitle As String, ByVal bAllowEmpty As Boolean)
    Dim strInput = String.Empty
    Dim strReturn = String.Empty

    Console.WriteLine(strTitle)
    strReturn = Console.ReadLine()
    
	While (String.IsNullOrEmpty(strReturn) And bAllowEmpty = False)
      strReturn = Console.ReadLine()
    End While

    ReadInput = strReturn
  End Function
End Class

There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/XmsToolkit.

NOTE: Demo Projects are created with Microsoft Visual Studio 2005

The MMS Toolkit project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft Visual Basic .NET. The projects are created with Microsoft Visual Studio 2005.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.