Solved

Urgent POP3 to Listbox example 500 Points

Posted on 2004-04-01
19
902 Views
Last Modified: 2010-05-18
Hi all,

I need an example of a POP3 clien that will collect the mails and put them in a LISTBOX.
Now, the emails are going to be sent to me separated by a semicolon between each field.
If it's possible i would like the example on a button click procedure to execute.
As i need it ASAP, i'm giving 500 points for it.

Thanks

SFern
0
Comment
Question by:sfern
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
  • +1
19 Comments
 
LVL 4

Expert Comment

by:k4hvd77
ID: 10730460
Could you explain what do you mean with "collect the mails and put them in a LISTBOX" and "the emails are going to be sent to me separated by a semicolon between each field"

what do you whant to put in a Listbox?? Email Sender, Body, Subject!!??
0
 
LVL 9

Expert Comment

by:mocarts
ID: 10730462
Hi SFern :)
what  you mean with "Now, the emails are going to be sent to me separated by a semicolon between each field."? do you need e-mail addresses collected in LISTBOX or email Subjects?
Can you explain what you need a bit more?

wbr, mo.
0
 

Author Comment

by:sfern
ID: 10731025
Well, i'm going to be sent and email with an ID, account no. etc on the body, this with be like 112;2344567;etc...i need to collect those email fields and separate them under individual headings on the listbox.

Sfern
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:mocarts
ID: 10731316
Hi
I have placed some sample App at http://www.grava.lv/files/pro/PopParse.zip
instead of LISTBOX we need to use ListView (to define columns) and I have used Indy Pop3 client component (you can download those components form http://www.indyproject.org/)

wbr, mo.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10731400
// provided Content-Type: text/plain


procedure TForm1.Button1Click(Sender: TObject);
begin
  if not IdPOP31.Connected then
    begin
    IdPOP31.Host := LabeledEdit1.Text;
    IdPOP31.Password := LabeledEdit2.Text;
    IdPOP31.Username := LabeledEdit3.Text;
    IdPOP31.Connect();
    end;
end;


procedure TForm1.Button3Click(Sender: TObject);
var
  idm: TIdMessage;
  mCount: integer;
  hc: integer;
  i: integer;
  j: integer;
  str: TStringList;
  li: TListItem;
  Line: string;
  Ptr: integer;
begin
  if IdPOP31.Connected then
    begin
    ListView1.Clear;
    str := TStringList.Create;
    mCount := IdPOP31.CheckMessages;
    idm :=TIdMessage.Create(Self);
    if mCount = 0 then
      begin
//      li := ListView1.Items.Add;
//      li.Caption := ' There is no messages ';
      end;
    for i := 1 to mCount do
      begin
//      li := ListView1.Items.Add;
//      li.Caption := '----------------------------';


      IdPOP31.Retrieve(i,idm);
      for j := 0 to idm.Body.Count-1 do
        begin
        Line := idm.Body[j];
        Ptr := Pos(';',Line);
        if Ptr > 0 then
          begin
          li := ListView1.Items.Add;
          li.Caption := Copy(Line,1,Ptr-1);
          Line := Copy(Line,Ptr+1,Length(Line));
          Ptr := Pos(';',Line);
          while Ptr > 0 do
            begin
            li.SubItems.Add(Copy(Line,1,Ptr-1));
            Line := Copy(Line,Ptr+1,Length(Line));
            Ptr := Pos(';',Line);
            end;
          if Length(Line) > 0 then
            begin
            li.SubItems.Add(Line);
            end;
          end
        else
//          li.Caption := 'Format error';
        end;

{
      IdPOP31.RetrieveRaw(i,str);
      for j := 0 to str.Count-1 do
        begin
        li := ListView1.Items.Add;
        li.Caption := str[j];
        end;
}

      end;
    idm.Free;
    str.Free;
    end;

end;
0
 

Author Comment

by:sfern
ID: 10731666
First of all thanks for your time but it still doesn't work.

1. mocarts, your's is only retreving 2 messages and only 2 fields but none from the body message, which are separated by semi-colons.

2. mokule, i tried yours and for some reason it's not working.

The emails that i would receive would look like this:

From: whoever@blablabla.com

Subject: whatever

Body: 1;1234567;Mr;Paul;Chingo

Now, the listview will have these headings:

ID, Account No.,Title, Firstname, Surname.

The text in the body would go under their corresponding listview columns, so in this example the listview would look like this:

ID  Account No.    Title  Firstname    Surname <--- Listview headers

1   1234567         Mr    Paul             Chingo


I hope that this will make it a bit clearer for you.

Thanks

SFern.

0
 
LVL 17

Expert Comment

by:mokule
ID: 10731816
I presume that You place TListView on a Form.
And Inserted columns manually at design time.

    IdPOP31.Host := 'blablabla.com';
    IdPOP31.Password := 'your password';
    IdPOP31.Username := 'whoever@blablabla.com';
    IdPOP31.Connect();

This should be done first
Important: e-mail must be Content-Type: text/plain    !!!!
I've tested it. It absolutly works.
0
 

Author Comment

by:sfern
ID: 10731839
OK i'll try again.

Thanks

0
 
LVL 17

Expert Comment

by:mokule
ID: 10731890
{ email body
Value1a;Value1b;Value1c;Value1d;Value1e
Value2a;Value2b;Value2c;Value2d;Value2e
Value3a;Value3b;Value3c;Value3d;Value3e
Value4a;Value4b;Value4c;Value4d;Value4e
Value5a;Value5b;Value5c;Value5d;Value5e
Value6a;Value6b;Value6c;Value6d;Value6e
}



unit MainPOP3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdMessageClient, IdPOP3, IdMessage,
  shellapi, ComCtrls;

type
  TForm1 = class(TForm)
    IdPOP31: TIdPOP3;
    Panel1: TPanel;
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    LabeledEdit3: TLabeledEdit;
    Button2: TButton;
    Button1: TButton;
    Button3: TButton;
    ListView1: TListView;
    procedure Button1Click(Sender: TObject);
    procedure IdPOP31Connected(Sender: TObject);
    procedure IdPOP31Disconnected(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not IdPOP31.Connected then
    begin
    IdPOP31.Host := LabeledEdit1.Text;
    IdPOP31.Password := LabeledEdit2.Text;
    IdPOP31.Username := LabeledEdit3.Text;
    IdPOP31.Connect();
    end;
end;

procedure TForm1.IdPOP31Connected(Sender: TObject);
begin
  Button2.Enabled := True;
  Button3.Enabled := True;
  Button1.Enabled := False;
end;

procedure TForm1.IdPOP31Disconnected(Sender: TObject);
begin
  Button2.Enabled := False;
  Button3.Enabled := False;
  Button1.Enabled := True;
end;


// provided Content-Type: text/plain

procedure TForm1.Button3Click(Sender: TObject);
var
  idm: TIdMessage;
  mCount: integer;
  hc: integer;
  i: integer;
  j: integer;
  str: TStringList;
  li: TListItem;
  Line: string;
  Ptr: integer;
begin
  if IdPOP31.Connected then
    begin
    ListView1.Clear;
    str := TStringList.Create;
    mCount := IdPOP31.CheckMessages;
    idm :=TIdMessage.Create(Self);
    if mCount = 0 then
      begin
//      li := ListView1.Items.Add;
//      li.Caption := ' There is no messages ';
      end;
    for i := 1 to mCount do
      begin
//      li := ListView1.Items.Add;
//      li.Caption := '----------------------------';


      IdPOP31.Retrieve(i,idm);
      for j := 0 to idm.Body.Count-1 do
        begin
        Line := idm.Body[j];
        Ptr := Pos(';',Line);
        if Ptr > 0 then
          begin
          li := ListView1.Items.Add;
          li.Caption := Copy(Line,1,Ptr-1);
          Line := Copy(Line,Ptr+1,Length(Line));
          Ptr := Pos(';',Line);
          while Ptr > 0 do
            begin
            li.SubItems.Add(Copy(Line,1,Ptr-1));
            Line := Copy(Line,Ptr+1,Length(Line));
            Ptr := Pos(';',Line);
            end;
          if Length(Line) > 0 then
            begin
            li.SubItems.Add(Line);
            end;
          end
        else
//          li.Caption := 'Format error';
        end;

{
      IdPOP31.RetrieveRaw(i,str);
      for j := 0 to str.Count-1 do
        begin
        li := ListView1.Items.Add;
        li.Caption := str[j];
        end;
}

      end;
    idm.Free;
    str.Free;
    end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if IdPOP31.Connected then
    IdPOP31.Disconnect;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if IdPOP31.Connected then
    IdPOP31.Disconnect;
end;

end.

//-------------------------------------- DFM

object Form1: TForm1
  Left = 223
  Top = 122
  Width = 544
  Height = 445
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 536
    Height = 89
    Align = alTop
    TabOrder = 0
    object LabeledEdit1: TLabeledEdit
      Left = 8
      Top = 24
      Width = 145
      Height = 21
      EditLabel.Width = 22
      EditLabel.Height = 13
      EditLabel.Caption = 'Host'
      TabOrder = 0
    end
    object LabeledEdit2: TLabeledEdit
      Left = 176
      Top = 24
      Width = 121
      Height = 21
      EditLabel.Width = 46
      EditLabel.Height = 13
      EditLabel.Caption = 'Password'
      TabOrder = 1
    end
    object LabeledEdit3: TLabeledEdit
      Left = 320
      Top = 24
      Width = 177
      Height = 21
      EditLabel.Width = 22
      EditLabel.Height = 13
      EditLabel.Caption = 'User'
      TabOrder = 2
    end
    object Button2: TButton
      Left = 104
      Top = 56
      Width = 75
      Height = 25
      Caption = 'Disconnect'
      Enabled = False
      TabOrder = 3
      OnClick = Button2Click
    end
    object Button1: TButton
      Left = 8
      Top = 56
      Width = 75
      Height = 25
      Caption = 'Connect'
      TabOrder = 4
      OnClick = Button1Click
    end
    object Button3: TButton
      Left = 200
      Top = 56
      Width = 75
      Height = 25
      Caption = 'Retrieve'
      Enabled = False
      TabOrder = 5
      OnClick = Button3Click
    end
  end
  object ListView1: TListView
    Left = 0
    Top = 89
    Width = 536
    Height = 322
    Align = alClient
    Columns = <
      item
        Caption = '1'
      end
      item
        Caption = '2'
      end
      item
        Caption = '3'
      end
      item
        Caption = '4'
      end
      item
        Caption = '5'
      end>
    TabOrder = 1
    ViewStyle = vsReport
  end
  object IdPOP31: TIdPOP3
    MaxLineAction = maException
    ReadTimeout = 0
    OnDisconnected = IdPOP31Disconnected
    Host = 'abak.win.pl'
    OnConnected = IdPOP31Connected
    Left = 304
    Top = 56
  end
end
0
 

Author Comment

by:sfern
ID: 10732063
I've sent plain text messages but it doesn't retrieve any at all and i know that they are there :(

When i'm i doing wrong then, it's not working?


0
 

Author Comment

by:sfern
ID: 10732140
Would it be possible for me to download the source itself from you, because i must be doing something wrong here.

Thanks

sfern
0
 
LVL 17

Expert Comment

by:mokule
ID: 10732201
I've posted all src pas file and dfm file. Didn't it work?
Send me e-mail with data to abak (at) abak win pl
I'll receive and tell You whether it populates ListView
0
 

Author Comment

by:sfern
ID: 10732409
I've sent you and email.
0
 

Author Comment

by:sfern
ID: 10732471
Did you get my email?
0
 
LVL 9

Accepted Solution

by:
mocarts earned 500 total points
ID: 10732545
hi, again
I have placed new version with some minor changes at http://www.grava.lv/files/pro/PopParse2.zip

about retrieving only two messages - did you removed test on Subject in code?

wbr, mo.
0
 

Author Comment

by:sfern
ID: 10732584
No i didn't....I'll check it out...thanks :)
0
 
LVL 17

Expert Comment

by:mokule
ID: 10732628
to sfern
I don't no Your post was for me, but I didn't receive anything.
Changed spaces with dots? and at with @?
0
 

Author Comment

by:sfern
ID: 10732802
Great It's working fine :)

Thanks much for you help !!!

SFern
0
 
LVL 9

Expert Comment

by:mocarts
ID: 10733029
you are welcome :)
wbr, mo.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month7 days, 15 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question