You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use MMS Toolkit > SMTP (MM4) > Visual Basic 5.x/6.x
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 Visual Basic projects.
Download the the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch 'Microsoft Visual Basic' from the Start menu, and choose 'New' from the 'File Menu'. The 'New Project' dialog appears.
Select 'Standard Exe' and click 'OK':
(Click on the picture to enlarge)
A new Project is created, with a blank form.
First, you must add a reference to the SMS and MMS Toolkit in the project to be able to use the MMS objects. To do so, choose 'References...' from the 'Project' menu. In the 'References' dialog that pops up, enable the 'ActiveXperts SMS and MMS Toolkit Type Library' reference as shown in the following picture:
(Click on the picture to enlarge)
Click 'OK' to close the 'References...' dialog.
Then, select the Project form and choose 'View Code' from the context menu:
(Click on the picture to enlarge)
On top of your code, declare the following objects for MM4:
Dim objMm4Protocol As AXmsCtrl.MmsProtocolMm4 Dim objMmsConstants As AXmsCtrl.MmsConstants Dim objMmsSlide As AXmsCtrl.MmsSlide Dim objMmsMessage As AXmsCtrl.MmsMessage
From the Code window, select 'Form'. The Private Sub 'Form_Load()' will be displayed now.
In the 'Form Load' function, create the MMS objects in the following way:
Set objMm4Protocol = CreateObject("ActiveXperts.MmsProtocolMm4")
Set objMmsConstants = CreateObject("ActiveXperts.MmsConstants")
Set objMmsMessage = CreateObject("ActiveXperts.MmsMessage")
Set objMmsSlide = CreateObject("ActiveXperts.MmsSlide")
The following code shows how to send MMS messages:
Option Explicit
'/////////////////////////////////////////////////////////////////////
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_PATH = 260
'/////////////////////////////////////////////////////////////////////
Dim objMm4Protocol As AXmsCtrl.MmsProtocolMm4
Dim objMmsConstants As AXmsCtrl.MmsConstants
Dim objMmsSlide As AXmsCtrl.MmsSlide
Dim objMmsMessage As AXmsCtrl.MmsMessage
'/////////////////////////////////////////////////////////////////////
Private Sub CheckAuthentication_Click()
EnableControls
End Sub
'/////////////////////////////////////////////////////////////////////
Private Sub CommandBrowse_Click()
CommonDialog1.DefaultExt = "GetAdsiDatabase"
CommonDialog1.DialogTitle = "Select Attachment"
CommonDialog1.Filter = "All Files (GetAdsiDatabase)|GetAdsiDatabase"
CommonDialog1.ShowOpen
TextImage.Text = CommonDialog1.FileName
End Sub
'/////////////////////////////////////////////////////////////////////
Private Sub CommandSend_Click()
MousePointer = vbHourglass
CommandSend.Enabled = False
' Server Properties
objMm4Protocol.ProviderHost = TextServer.Text
objMm4Protocol.ProviderPort = CInt(TextPort.Text)
If (CheckAuthentication.Value <> 0) Then
objMm4Protocol.ProviderAccount = TextAccount.Text
objMm4Protocol.ProviderPassword = TextPassword.Text
Else
objMm4Protocol.ProviderAccount = ""
objMm4Protocol.ProviderPassword = ""
End If
' Logfile
objMm4Protocol.LogFile = TextLogfile.Text
'Message Properties
objMmsMessage.Clear
objMmsMessage.AddRecipient TextTo.Text
objMmsMessage.From = TextFrom.Text
objMmsMessage.Subject = TextSubject.Text
objMmsSlide.Duration = 5
objMmsSlide.AddAttachment TextImage.Text
objMmsSlide.AddText TextBody.Text
objMmsMessage.AddSlide objMmsSlide
objMm4Protocol.Send objMmsMessage
TextResult.Text = "ERROR #" & objMm4Protocol.LastError & " : " & objMm4Protocol.GetErrorDescription(objMm4Protocol.LastError)
TextResponse.Text = objMm4Protocol.ProviderResponse
CommandSend.Enabled = True
MousePointer = vbDefault
End Sub
'/////////////////////////////////////////////////////////////////////
Private Sub CommandView_Click()
If FileExists(TextLogfile.Text) = True Then
Shell "notepad " + TextLogfile.Text, vbNormalFocus
End If
End Sub
'/////////////////////////////////////////////////////////////////////
Private Sub Form_Load()
Set objMm4Protocol = CreateObject("ActiveXperts.MmsProtocolMm4")
Set objMmsConstants = CreateObject("ActiveXperts.MmsConstants")
Set objMmsMessage = CreateObject("ActiveXperts.MmsMessage")
Set objMmsSlide = CreateObject("ActiveXperts.MmsSlide")
EnableControls
SetDefaultLogFile
End Sub
'/////////////////////////////////////////////////////////////////////
Public Function FileExists(sFileName As String) As Boolean
FileExists = CBool(Len(Dir$(sFileName))) And CBool(Len(sFileName))
End Function
'/////////////////////////////////////////////////////////////////////
Private Function SetDefaultLogFile()
Dim Buffer As String
Buffer = Space(MAX_PATH)
If GetTempPath(MAX_PATH, Buffer) <> 0 Then
TextLogfile.Text = Left$(Buffer, InStr(Buffer, vbNullChar) - 1) & "MM4Log.txt"
Else
TextLogfile.Text = "C:\MM4Log.txt"
End If
End Function
'/////////////////////////////////////////////////////////////////////
Private Sub EnableControls()
TextAccount.Enabled = CheckAuthentication.Value
TextPassword.Enabled = CheckAuthentication.Value
LabelAccount.Enabled = CheckAuthentication.Value
LabelPassword.Enabled = CheckAuthentication.Value
End Sub
'/////////////////////////////////////////////////////////////////////
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.