Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 911
  • Last Modified:

Urgent POP3 to Listbox example 500 Points

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
sfern
Asked:
sfern
  • 9
  • 5
  • 4
  • +1
1 Solution
 
k4hvd77Commented:
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
 
mocartsCommented:
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
 
sfernAuthor Commented:
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
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!

 
mocartsCommented:
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
 
mokuleCommented:
// 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
 
sfernAuthor Commented:
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
 
mokuleCommented:
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
 
sfernAuthor Commented:
OK i'll try again.

Thanks

0
 
mokuleCommented:
{ 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
 
sfernAuthor Commented:
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
 
sfernAuthor Commented:
Would it be possible for me to download the source itself from you, because i must be doing something wrong here.

Thanks

sfern
0
 
mokuleCommented:
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
 
sfernAuthor Commented:
I've sent you and email.
0
 
sfernAuthor Commented:
Did you get my email?
0
 
mocartsCommented:
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
 
sfernAuthor Commented:
No i didn't....I'll check it out...thanks :)
0
 
mokuleCommented:
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
 
sfernAuthor Commented:
Great It's working fine :)

Thanks much for you help !!!

SFern
0
 
mocartsCommented:
you are welcome :)
wbr, mo.
0

Featured Post

Technology Partners: 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!

  • 9
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now