Here is a checklist on what you need:
-Borland Delphi
-Installed Indy components (these are automatically installed if you are using Delphi 6 or Delphi 7)
Onward!
Create a new project in Delphi.
Select the Indy “IdPop3” component from the “Indy Clients” tab and place it on your form.

Now, we need to make this component work. We will use this component to check our inbox when our program starts, and to do that, double click any part of the empty area on your form, and the code editor will show up allowing you to type the code that will be executed as soon as the form is created.

First, we need to define the variable that is going to contain the number of new messages. In this case, I called it “Status”. When defining variables in Delphi, you need to put them behind the main “begin” statement of the procedure, like this:
CODE
procedure TForm1.FormCreate(Sender: TObject);
var Status:Integer;
begin
end;
This program will automatically end after we click on the OK button after we receive our notification, but the main form will still show up and hide itself very fast, which looks a bit ugly. So we will resize it and move it to the invisible part of the screen:
CODE
Form1.Width := 100;
Form1.Height := 100;
Form1.Left := -500;
Form1.Top := -500;
Good. Now we need to input the needed information about the pop3 server that we are connecting to. Don’t forget to type in your information here:
CODE
idPop31.Username := 'your_username';
idpop31.Password := 'your_password';
idpop31.Host := 'pop3.your_server.com';
Now for the code that will connect and retrieve the needed information. First we connect to the server, then the “idpop3” components retrieves the number of new messages, and disconnects from the server:
CODE
idpop31.Connect;
Status:=idpop31.CheckMessages;
idpop31.Disconnect;
Let’s show our notification:
If the number of messages is 0, the program will play a sound and show a message box that will inform us that we do not have any new messages. In this case, I used the “Windows XP Logoff” sound, but you can use any sound you like, as long as it is a WAV file:
IMPORTANT: In order to play the sound, you need to place the “mmsystem” unit in the “Uses” form:

CODE
if Status = 0 then
begin
PlaySound('C:\WINDOWS\Media\Windows XP Logoff Sound.wav',0,SND_ASYNC);
MessageDlg('You have no new messages.',mtInformation,[mbOK],0);
end;
If the message count is 1, then the program plays the “Windows XP Logon” sound and shows a notification message:
CODE
if Status = 1 then
begin
PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC);
MessageDlg('You have 1 new message.',mtInformation,[mbOK],0);
end;
If the message count is larger than 1, then we do the same thing, except the message is slightly different:
CODE
if Status > 1 then
begin
PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC);
MessageDlg('You have '+IntToStr(Status)+' new messages.',mtInformation,[mbOK],0);
end;
And finally, we close our program with this piece of code:
CODE
Application.Terminate;
The whole unit should look like this:
CODE
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdPOP3, mmsystem;
type
TForm1 = class(TForm)
IdPOP31: TIdPOP3;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var Status:Integer;
begin
Form1.Width := 100;
Form1.Height := 100;
Form1.Left := -500;
Form1.Top := -500;
idPop31.Username := 'your_username';
idpop31.Password := 'your_password';
idpop31.Host := 'pop3.your_server.com';
idpop31.Connect;
Status:=idpop31.CheckMessages;
idpop31.Disconnect;
if Status = 0 then
begin
PlaySound('C:\WINDOWS\Media\Windows XP Logoff Sound.wav',0,SND_ASYNC);
MessageDlg('You have no new messages.',mtInformation,[mbOK],0);
end;
if Status = 1 then
begin
PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC);
MessageDlg('You have 1 new message.',mtInformation,[mbOK],0);
end;
if Status > 1 then
begin
PlaySound('C:\WINDOWS\Media\Windows XP Logon Sound.wav',0,SND_ASYNC);
MessageDlg('You have '+IntToStr(Status)+' new messages.',mtInformation,[mbOK],0);
end;
Application.Terminate;
end;
end.
Press F9 to run your program. If all goes as planned, the program will connect to your e-mail server and retrieve the number of new messages and display it as a dialog message:

That’s about it! Any questions and comments are welcome.

