ANPOP Developers Center > Using ANPOP3 in Delphi

You should download the anpop installer and install it on your machine at first. If you want to distribute or deploy anpop without anpop installer, please click here to learn more.

Add reference of ANPOP to your project

First of all, make sure ANPOP has been installed on your machine. Now start to create a standard delphi project: select menu "Project" -> "Import Type Library", checked "ANPOP POP3 COMPONENT BUILD" and click "Create Unit".

Using ANPOP in your project

The following code demonstrates how to declare and define objects in your project.

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ANPOPLib_TLB, StdCtrls, StrUtils;

....
var 
  m_oPop3 : TPOPMAIN;
  m_oMsg : TPOPMSG;
  m_oStore: TMSGSTORE;

procedure TForm1.FormCreate(Sender: TObject);
begin
   m_oSmtp := TPOPMAIN.Create(Form1);
   m_oMsg := TPOPMSG.Create(Form1);
   m_oStore: = TMSGSTORE.Create(Form1);
end;
					

Although you can create new object instance each time, we recommend declare object as member variable and create it in FormCreate subroutine so that you can reuse those member variables again without re-create it.

Asynchronous mode and event driving

If you want to use POPMAIN of ANPOP in asynchronous mode, you MUST bind events like this:

procedure TForm1.BindEvents();
begin
  m_oPop3 := TPOPMAIN.Create(Form1);
  //bind events to POPMAIN object
  m_oPop3.OnConnected := OnConnected;
  m_oPop3.OnClosed := OnClosed;
  m_oPop3.OnReceiving := OnReceiving;
  m_oPop3.OnRetrieved := OnRetrieved;
  m_oPop3.OnRetrieve := OnRetrieve;
  m_oPop3.OnGetMsgID := OnGetMsgID;
  m_oPop3.OnError := OnError;
  m_oPop3.OnGetTotalOfMails := OnGetTotalOfMails;
  m_oPop3.OnDeleted := OnDeleted;
end;

And you also need to define the following procedures to handle those events

procedure TForm1.OnConnected(Sender: TObject);
begin
// Add your implementation code
end;

procedure TForm1.OnClosed(Sender: TObject);
begin
// Add your implementation code
end;

procedure TForm1.OnReceiving(Sender: TObject; lBytes: Integer; lMsg: Integer);
begin
// Add your implementation code
end;

procedure TForm1.OnDeleted(Sender: TObject; lMsg: Integer);
begin
// Add your implementation code
end;

procedure TForm1.OnGetMsgID( Sender: TObject; const messageId: WideString; lMsg: Integer );
begin
// Add your implementation code
end;

procedure TForm1.OnGetTotalOfMails( Sender: TObject; lCount: Integer );
begin
// Add your implementation code
end;

procedure TForm1.OnRetrieve( Sender: TObject; lMsg: Integer );
begin
// Add your implementation code
end;

procedure TForm1.OnRetrieved(Sender: TObject; const emailContent: WideString; lMsg: Integer );
begin
// Add your implementation code
end;

procedure TForm1.OnError( Sender: TObject; lError: Integer; const ErrDescription: WideString );
begin
// Add your implementation code
end;

Note*: You SHOULD NOT invoke Connect1 method any more while POPMAIN is connecting with pop3 server, otherwise this connection would be terminated automatically.

A Total Sample

This sample demonstrates how to retrieve and parse email with asynchronous mode, click here to download. This sample is developed with Delphi 7.0

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2010 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map