你的错误在于你太快去执行pop.retrieve,很可能此时,程序正在通过校验,
还未通过,你就发命令,所以出错
等一阵,确保通过校验,然后就可以retrieve
我的程序如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdMessageClient, IdPOP3, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    IdPOP31: TIdPOP3;
    IdMessage1: TIdMessage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure IdPOP31Status(axSender: TObject; const axStatus: TIdStatus;
      const asStatusText: String);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
        IdPop31.Host:='263.net';
        IdPop31.UserId:='ch81';
        IdPop31.Password:='....';
        IdPop31.Connect
end;procedure TForm1.Button2Click(Sender: TObject);
begin
        if IdPop31.Connected then
        begin
                ShowMessage(inttostr(IdPop31.CheckMessages));
                ShowMessage('hello');
                IdPop31.Retrieve(1,IdMessage1);
        end;
        ShowMessage(IdMessage1.Body.Text);
        ShowMessage(IdMessage1.Subject);
end;procedure TForm1.IdPOP31Status(axSender: TObject;
  const axStatus: TIdStatus; const asStatusText: String);
begin
        ShowMessage(asStatusText);
end;end.

解决方案 »

  1.   

    还是不行,我是要把BODY。TEXT加到MEMO里去
    Memo1.Lines.AddStrings(TIdText(IdMessage1.MessageParts.Items[1]).Body);执行的时候错误提示是“List index out of bounds[1];
      

  2.   

    你要获取数组有几项!!你要获得它的count
    yypp(彭哥) :
    Starline是不是你?
    下面的程序,运行成功win2000+delphi6,现在没问题了把?unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
      IdTCPClient, IdMessageClient, IdPOP3, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        IdPOP31: TIdPOP3;
        IdMessage1: TIdMessage;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure IdPOP31Status(axSender: TObject; const axStatus: TIdStatus;
          const asStatusText: String);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
            IdPop31.Host:='263.net';
            IdPop31.UserId:='ch81';
            IdPop31.Password:='';
            IdPop31.Connect
    end;procedure TForm1.Button2Click(Sender: TObject);
    var i:integer;
    begin
            if IdPop31.Connected then
            begin
                    ShowMessage(inttostr(IdPop31.CheckMessages));
                    ShowMessage('hello');
                    IdPop31.Retrieve(1,IdMessage1);
            end;
            ShowMessage(IdMessage1.Body.Text);
            ShowMessage(inttostr(IdMessage1.MessageParts.Count));
            for i:=0 to IdMessage1.MessageParts.Count-1 do
            begin
                   ShowMessage(TIdText(IdMessage1.MessageParts.Items[i]).Body.Text);
            end;
            //ShowMessage(TIdText(IdMessage1.MessageParts.Items[0]).Body.Text);
            //ShowMessage(TIdText(IdMessage1.MessageParts.Items[1]).Body.Text);
            ShowMessage(IdMessage1.Subject);
    end;procedure TForm1.IdPOP31Status(axSender: TObject;
      const axStatus: TIdStatus; const asStatusText: String);
    begin
            ShowMessage(asStatusText);
    end;end.
      

  3.   

    我看不出你这次贴的程序和前面贴的有什么区别
    这次就是加了个循环,而且你通过BODY。TEXT获取的只是一行,
    而我的需求:
    比如,我现在需要把第三封信的正文内容添加到一个MEMO里去
    你能不能出代码来帮帮我?先谢了
      

  4.   

    for i:=0 to IdMessage1.MessageParts.Count-1 do
    begin
            ShowMessage(TIdText(IdMessage1.MessageParts.Items[i]).Body.Text);
    end;
    你不是老List index out of bounds[1]; 吗?
    这是你访问了数组以外的东西!用count先确定数组里面有几项!
    然后一次返问
    你把showmessage改为memo1.lines.add,不就行啦?我又试了几次,发现有一些邮件段落数为0,所以你会出错!
    而且subject为空,而且发信人也为空,可能是indy的控件,有问题
    有些邮件解码没解成功,或者是电子邮局的事而且还要告诉你正文,不一定是第二个段落IdMessage1.MessageParts.Items[1]).Body
    不带附件,正文是第一个段落IdMessage1.MessageParts.Items[0]).Body
    呆附件后,正文的位置就不定拉,各个段落都有可能!
    呆附件,就很烦啦!我有一封信,有6个段落,怎么判断????
    要如何判断那个段落是正文,好像除了一各个试,没太好的方法!
    所以:
    if IdMessage1.MessageParts.Count=0 then
    begin
         ShowMessage('Error mail');
         exit;
    end;
    if IdMessage1.MessageParts.Count=1 then
    begin
    Memo1.lines.add(TIdText(IdMessage1.MessageParts.Items[0]).Body.Text);
    exit;
    end;
    for i:=0 to IdMessage1.MessageParts.Count-1 do
    begin
          Memo1.lines.add(TIdText(IdMessage1.MessageParts.Items[i]).Body.Text);
    end;
    主要是段落一多后,那个段落是正文好象判断难度比较大!
      

  5.   

    INDY控件在这个方面就没有FASTNET做得好