You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > SMTP (MM4) > Delphi
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 Delphi 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 Borland Delphi (for instance 'Delphi 7') from the Start menu. Choose 'New' from the 'File' menu and select your preferred kind of application, for instance: 'VCL Forms Application - Delphi for Win32'. A new Form is displayed in the workspace.
(Click on the picture to enlarge)
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 SMS and MMS Toolkit objects. To do so, choose 'Import Type Library' from the 'Project' menu. The 'Import Type Library' dialog appears:
(Click on the picture to enlarge)
Select the 'ActiveXperts SMS and MMS Toolkit 2.1 Type Library' and click 'Create Unit'. The interface code is generated now and is shown in the AXmsCtrl_TLB tab of the project.
From the Project Manager, open Unit1.bas and add the AXmsCtrl_TLB to the 'Uses' statement to refer to the SMS and MMS Toolkit library:
(Click on the picture to enlarge)
In the 'private' or 'public' section, declare the following objects:
objMm4Protocol : IMmsProtocolMm4; objMmsMessage : IMmsMessage; objMmsSlide : IMmsSlide; objMmsConstants : IMmsConstants;
You can now create the objects, for instance in the 'FormCreate' function:
objMm4Protocol := TMmsProtocolMm4.Create(Form1).DefaultInterface; objMmsMessage := TMmsMessage.Create(Form1).DefaultInterface; objMmsSlide := TMmsSlide.Create(Form1).DefaultInterface; objMmsConstants := TMmsConstants.Create(Form1).DefaultInterface
You can now send MMS messages.
The following code shows how to send a MMS message using a MM7 (SOAP) connection:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AXmsCtrl_TLB, StdCtrls, ShellAPI, ExtCtrls;
type
TForm1 = class(TForm)
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
EditResult: TEdit;
EditResponse: TEdit;
EditLogfile: TEdit;
ButtonLoadCfg: TButton;
ButtonSaveCfg: TButton;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
ButtonSend: TButton;
EditTo: TEdit;
EditSubject: TEdit;
EditBody: TMemo;
EditImage: TEdit;
ButtonBrowse: TButton;
ButtonView: TButton;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
Label1: TLabel;
EditURL: TEdit;
CheckSSL: TCheckBox;
CheckAuthentication: TCheckBox;
LabelAccount: TLabel;
LabelPassword: TLabel;
EditAccount: TEdit;
EditPassword: TEdit;
Panel1: TPanel;
Panel2: TPanel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
ComboVariation: TComboBox;
ComboSchema: TComboBox;
ComboVersion: TComboBox;
function GetResult : Integer;
procedure EnableControls ();
procedure FormCreate(Sender: TObject);
procedure ButtonViewClick(Sender: TObject);
procedure ButtonSendClick(Sender: TObject);
procedure ButtonLoadCfgClick(Sender: TObject);
procedure ButtonSaveCfgClick(Sender: TObject);
procedure ButtonBrowseClick(Sender: TObject);
function GetTempDirectory: string;
procedure CheckAuthenticationClick(Sender: TObject);
private
objMm4Protocol : IMM7Connection;
objMmsMessage : IMmsMessage;
objMmsSlide : IMmsSlide;
objMmsConstants : IMmsConstants;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.FormCreate(Sender: TObject);
begin
objMm4Protocol := TMM7Connection.Create(Form1).DefaultInterface;
objMmsMessage := TMmsMessage.Create(Form1).DefaultInterface;
objMmsSlide := TMmsSlide.Create(Form1).DefaultInterface;
objMmsConstants := TMmsConstants.Create(Form1).DefaultInterface;
ComboVariation.Items.Add ('3GPP');
ComboVariation.Items.Add ('Ericsson');
ComboVariation.Items.Add ('PAP');
ComboVariation.ItemIndex := 0;
ComboSchema.Items.Add ('REL-5-MM7-1-0');
ComboSchema.Items.Add ('REL-5-MM7-1-1');
ComboSchema.Items.Add ('REL-5-MM7-1-2');
ComboSchema.Items.Add ('REL-5-MM7-1-3');
ComboSchema.Items.Add ('REL-5-MM7-1-4');
ComboSchema.Items.Add ('REL-5-MM7-1-5');
ComboSchema.Items.Add ('REL-6-MM7-1-0');
ComboSchema.Items.Add ('REL-6-MM7-1-1');
ComboSchema.Items.Add ('REL-6-MM7-1-2');
ComboSchema.Items.Add ('REL-6-MM7-1-3');
ComboSchema.ItemIndex := 0;
ComboVersion.Items.Add ( '5.2.0' );
ComboVersion.Items.Add ( '5.3.0' );
ComboVersion.Items.Add ( '5.4.0' );
ComboVersion.Items.Add ( '5.5.0' );
ComboVersion.Items.Add ( '5.6.0' );
ComboVersion.Items.Add ( '5.7.0' );
ComboVersion.Items.Add ( '5.8.0' );
ComboVersion.Items.Add ( '5.9.0' );
ComboVersion.Items.Add ( '5.10.0' );
ComboVersion.Items.Add ( '5.11.0' );
ComboVersion.Items.Add ( '6.0.0' );
ComboVersion.Items.Add ( '6.1.0' );
ComboVersion.Items.Add ( '6.2.0' );
ComboVersion.Items.Add ( '6.3.0' );
ComboVersion.Items.Add ( '6.4.0' );
ComboVersion.Items.Add ( '6.5.0' );
ComboVersion.Items.Add ( '6.6.0' );
ComboVersion.Items.Add ( '6.7.0' );
ComboVersion.ItemIndex := 0;
EnableControls ();
GetTempDirectory ();
end;
{ //////////////////////////////////////////////////////////////////////////////// }
function TForm1.GetResult : Integer;
begin
Result := objMm4Protocol.LastError;
EditResponse.Text := objMm4Protocol.ProviderResponse;
EditResult.Text := 'ERROR ' + IntToStr ( Result ) + ' : ' + objMm4Protocol.GetErrorDescription( Result );
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.ButtonViewClick(Sender: TObject);
var LogFile : PAnsiChar;
begin
LogFile := StrNew(PChar(EditLogfile.Text));
ShellExecute ( 0, 'open' , LogFile, '', '', SW_SHOW )
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.ButtonSendClick(Sender: TObject);
var vtVar : OleVariant;
begin
ButtonSend.Enabled := False;
Cursor := crHourGlass;
{ Set Connection Properties }
objMm4Protocol.Clear ();
objMm4Protocol.ProviderURL := EditURL.Text;
objMm4Protocol.ProviderAccount := EditAccount.Text;
objMm4Protocol.ProviderPassword := EditPassword.Text;
objMm4Protocol.ProviderMM7Version := ComboVersion.ItemIndex;
objMm4Protocol.ProviderMM7Schema := ComboSchema.ItemIndex;
objMm4Protocol.ProviderMM7Variation:= ComboVariation.ItemIndex;
objMm4Protocol.LogFile := EditLogfile.Text;
if ( CheckSSL.Checked = true ) then begin
objMm4Protocol.ProviderUseSSL := 1;
end;
{ Set Message Properties }
objMmsMessage.AddRecipient(EditTo.Text);
objMmsMessage.Subject := EditSubject.Text;
{ Create First Slide }
vtVar := 0;
objMmsSlide.AddText(EditBody.Text);
objMmsSlide.AddAttachment (EditImage.Text, vtVar );
vtVar := objMmsSlide;
objMmsMessage.AddSlide(vtVar);
vtVar := objMmsMessage;
{ Send the message }
objMm4Protocol.Send(vtVar);
GetResult ();
ButtonSend.Enabled := True;
Cursor := crDefault;
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.ButtonLoadCfgClick(Sender: TObject);
begin
OpenDialog.DefaultExt := '.mm7';
OpenDialog.Filter := 'MMS Connection Files|*.mm7';
if OpenDialog.Execute = true Then begin
objMm4Protocol.ProviderProviderLoadConfig (OpenDialog.FileName);
if ( GetResult() = 0) then begin
EditURL.Text := objMm4Protocol.ProviderURL;
EditAccount.Text := objMm4Protocol.ProviderAccount;
EditPassword.Text := objMm4Protocol.ProviderPassword;
ComboVersion.ItemIndex := objMm4Protocol.ProviderMM7Version;
ComboSchema.ItemIndex := objMm4Protocol.ProviderMM7Schema;
ComboVariation.ItemIndex := objMm4Protocol.ProviderMM7Variation;
CheckSSL.Checked := Boolean (objMm4Protocol.ProviderUseSSL);
if ( StrLen ( PChar(EditAccount.Text) ) > 0 ) then begin
CheckAuthentication.Checked := true;
end;
end;
end;
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.ButtonSaveCfgClick(Sender: TObject);
begin
SaveDialog.DefaultExt := '.mm7';
SaveDialog.Filter := 'MMS Connection Files|*.mm7';
if SaveDialog.Execute = true then begin
objMm4Protocol.ProviderURL := EditURL.Text;
objMm4Protocol.ProviderAccount := EditAccount.Text;
objMm4Protocol.ProviderPassword := EditPassword.Text;
objMm4Protocol.ProviderMM7Version := ComboVersion.ItemIndex;
objMm4Protocol.ProviderMM7Schema := ComboSchema.ItemIndex;
objMm4Protocol.ProviderMM7Variation:= ComboVariation.ItemIndex;
objMm4Protocol.ProviderUseSSL := Integer (CheckSSL.Checked);
objMm4Protocol.ProviderSaveConfig(SaveDialog.FileName);
GetResult ();
end;
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.ButtonBrowseClick(Sender: TObject);
begin
OpenDialog.DefaultExt := '.jpg';
OpenDialog.Filter := 'Image Files|*.jpg';
if OpenDialog.Execute = true Then begin
EditImage.Text := OpenDialog.FileName;
end;
end;
{ //////////////////////////////////////////////////////////////////////////////// }
function TForm1.GetTempDirectory: string;
var Buffer: array[0..MAX_PATH] of Char;
begin
GetTempPath(SizeOf(Buffer) - 1, Buffer);
EditLogfile.Text := StrPas(Buffer) + 'MmsLog.txt';
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.EnableControls ();
begin
LabelAccount.Enabled := CheckAuthentication.Checked;
LabelPassword.Enabled := CheckAuthentication.Checked;
EditAccount.Enabled := CheckAuthentication.Checked;
EditPassword.Enabled := CheckAuthentication.Checked;
end;
{ //////////////////////////////////////////////////////////////////////////////// }
procedure TForm1.CheckAuthenticationClick(Sender: TObject);
begin
EnableCOntrols();
end;
{ //////////////////////////////////////////////////////////////////////////////// }
end.
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.
The MMS Toolkit project ships with a set of samples for Borland Delphi. The projects are created with Borland Delphi 7.
Users with a later version of Borland Delphi 7 can open such a project. The Borland Conversion Wizard will guide you through the process of converting the project to the version used.