Quicklinks
ActiveEmail SMTP/POP3 Toolkit is a software development kit (SDK) that enables the user to send (SMTP) and receive (POP3) e-mail messages. ActiveEmail supports SMTP, POP3, multiple recipients (To, CC, BCC), multiple attachments (ASCII and binary), rich text body formats (RTF/HTML), Unicode, multiple character sets, SMTP authorization (AUTH PLAIN, AUTH LOGIN, AUTH CRAM MD5), POP3 authorization (Plain, APOP), POP3 header download, different character sets (including arabic, chinese, japanese, russian, greek and many more), different encodings (including 7/8 bit, quoted-printable, base64).
ActiveEmail can be well integrated into Borland Delphi environments. This document describes how ActiveEmail can be integrated into Borland Delphi projects.
Download the ActiveEmail SMTP/POP3 Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Borland Delphi (for instance 'Delphi 2005') 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 ActiveEmail in the project to be able to use the ActiveEmail object. To do so, choose 'Import Component...' from the 'Component' menu. The Import Components' dialog appears. Select 'Import a Type Library':
(Click on the picture to enlarge)
In the 'Registered Type Libraries' page, select 'ActiveEmail 3.1 Type Library' and click 'Next':
(Click on the picture to enlarge)
In the 'Components' page, leave all fields default and click 'Next':
(Click on the picture to enlarge)
In the 'Install' page, select 'Create Unit' and click 'Next':
(Click on the picture to enlarge)
The interface code is generated now and is shown in the AEMAILLib_TLB tab of the project.
From the Project Manager, open Unit1.pas and add the AEMAILLib_TLB to the 'Uses' statement to refer to the ActiveEmail library:
(Click on the picture to enlarge)
In the 'private' or 'public' section, declare the following objects:
objSmtpServer : ISmtpServer; objSmtpMail : ISmtpMail; objConstants : IEmailConstants;
You can now create the objects, for instance in the 'FormCreate' function:
objSmtpServer := TSmtpServer.Create ( Form1 ).DefaultInterface; objSmtpMail := TSmtpMail.Create ( Form1 ).DefaultInterface; objConstants := TEmailConstants.Create ( Form1 ).DefaultInterface;
You can now send email messages using a SMTP server.
The following code shows how to send an email messages:
unit UnitSmtp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI, Registry, AEMAILLib_TLB;
type
TFormSmtp = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
editServer: TEdit;
checkAuth: TCheckBox;
editPassword: TEdit;
editFromName: TEdit;
editFromAddress: TEdit;
editAccount: TEdit;
GroupBox2: TGroupBox;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
editMailTo: TEdit;
editSubject: TEdit;
editBody: TEdit;
comboEncoding: TComboBox;
comboFormat: TComboBox;
comboPriority: TComboBox;
buttonSend: TButton;
GroupBox3: TGroupBox;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
editResult: TEdit;
editLogfile: TEdit;
buttonView: TButton;
editResponse: TMemo;
procedure buttonSendClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure buttonViewClick(Sender: TObject);
procedure checkAuthClick(Sender: TObject);
function GetResult : Integer;
function GetTempDirectory: string;
private
objSmtpServer : ISmtpServer;
objSmtpMail : ISmtpMail;
objSmtpConst : IEmailConstants;
public
{ Public declarations }
end;
var
FormSmtp: TFormSmtp;
implementation
{///////////////////////////////////////////////////////////////////////////////}
{$R *.dfm}
{///////////////////////////////////////////////////////////////////////////////}
procedure TFormSmtp.buttonSendClick(Sender: TObject);
var vtVar : OleVariant;
var Save_Cursor:TCursor;
begin
objSmtpServer.LogFile := editLogfile.Text;
Save_Cursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
if checkAuth.Checked = true then begin
objSmtpServer.Connect(editServer.Text, editAccount.Text, editPassword.Text);
end
else
begin
objSmtpServer.Connect ( editServer.Text , '', '' );
end;
if GetResult = 0 then begin
objSmtpMail.Clear ();
objSmtpMail.Subject := editSubject.Text;
objSmtpMail.Body := editBody.Text;
objSmtpMail.FromName := editFromName.Text;
objSmtpMail.FromAddress := editFromAddress.Text;
objSmtpMail.AddTo( editMailTo.Text, '');
objSmtpMail.BodyType := comboFormat.ItemIndex;
objSmtpMail.Priority := comboPriority.ItemIndex + 1;
if comboEncoding.ItemIndex = 1 then objSmtpMail.Encoding := objSmtpConst.asMESSAGE_ENCODING_UTF8
else objSmtpMail.Encoding:= objSmtpConst.asMESSAGE_ENCODING_DEFAULT;
vtVar := objSmtpMail;
objSmtpServer.Send ( vtVar );
GetResult;
objSmtpServer.Disconnect();
Screen.Cursor := Save_Cursor;
end;
end;
{///////////////////////////////////////////////////////////////////////////////}
procedure TFormSmtp.FormCreate(Sender: TObject);
begin
objSmtpServer := TSmtpServer.Create ( Form1 ).DefaultInterface;
objSmtpMail := TSmtpMail.Create ( Form1 ).DefaultInterface;
objConstants := TEmailConstants.Create ( Form1 ).DefaultInterface;
comboFormat.Items.Add('Plain');
comboFormat.Items.Add('HTML');
comboFormat.ItemIndex := 0;
comboPriority.Items.Add ('Lowest');
comboPriority.Items.Add ('Low');
comboPriority.Items.Add('Medium');
comboPriority.Items.Add('High');
comboPriority.Items.Add('Highest');
comboPriority.ItemIndex := 2;
comboEncoding.Items.Add ('Default');
comboEncoding.Items.Add( 'UTF-8');
comboEncoding.ItemIndex := 0;
GetTempDirectory ();
end;
{///////////////////////////////////////////////////////////////////////////////}
procedure TFormSmtp.buttonViewClick(Sender: TObject);
var LogFile : PAnsiChar;
begin
LogFile := StrNew(PChar(editLogfile.Text));
ShellExecute ( 0, 'open' , LogFile, '', '', SW_SHOW )
end;
{///////////////////////////////////////////////////////////////////////////////}
procedure TFormSmtp.checkAuthClick(Sender: TObject);
begin
editAccount.Enabled := checkAuth.Checked;
editPassword.Enabled := checkAuth.Checked;
end;
{///////////////////////////////////////////////////////////////////////////////}
function TFormSmtp.GetTempDirectory: string;
var Buffer: array[0..MAX_PATH] of Char;
begin
GetTempPath(SizeOf(Buffer) - 1, Buffer);
editLogfile.Text := StrPas(Buffer) + 'SmtpLog.txt';
end;
{///////////////////////////////////////////////////////////////////////////////}
function TFormSmtp.GetResult : Integer;
begin
Result := objSmtpServer.LastError;
editResult.Text := IntToStr ( Result ) + ' : ' + objSmtpServer.GetErrorDescription( Result );
editResponse.Text := objSmtpServer.LastSmtpResponse;
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/aemail.
The ActiveComport 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.