我用delphi7+POP3开发邮件接收程序,不知道怎样得到每个邮件的标题。另外怎样读邮件的同时删除服务器上的备份。

解决方案 »

  1.   

    //连接邮件服务器获得邮件数量
      try
        self.POP3GetMailInfo.Connect(5000);
        self.Status.Caption:='连接服务器成功...';
        mailCount:=self.POP3GetMailInfo.CheckMessages;
        self.Status.Caption:='共'+inttostr(mailCount)+'封邮件';
        self.POP3GetMailInfo.Disconnect;
      except
        self.Status.Caption:='连接服务器失败...';
      end;//接收邮件
    var
       intIndex,j: integer;
       itm: TListItem;
       tempCaption,
       tempSubject,
       tempRetrieveMsgSize,
       tempDate,
       FileDate:string;
    begin
      lvMailBox.Items.Clear;
      for intIndex := 1 to inMsgCount do
      begin
        self.Status.Caption:='正在接收第'+inttostr(intindex)+'封邮件,(共'+inttostr(self.mailCount)+')封邮件';
        Application.ProcessMessages;
        Msg.Clear;
        Pop3GetmailInfo.Retrieve(IntIndex,msg);    tempCaption:=Msg.From.Text;
        tempSubject:=Msg.Subject;
        tempRetrieveMsgSize:=IntToStr(POP3GetMailInfo.RetrieveMsgSize(intIndex));
        tempDate:=formatdatetime('yyyy-mm-dd hh:mm:ss',Msg.Date);
        FileDate:=formatdatetime('yyyymmddhhmmss',Msg.Date);    itm := lvMailBox.Items.Add;
        itm.ImageIndex := 5;
        itm.SubItems.Add(tempCaption);
        itm.SubItems.Add(tempSubject);
        itm.SubItems.Add(tempDate);//   DateToStr(Msg.Date));
        itm.SubItems.Add(tempRetrieveMsgSize);
    //接收附件
        for j := 0 to Pred(Msg.MessageParts.Count) do
          if (Msg.MessageParts.Items[j] is TIdAttachment) then
          begin
            tempCaption:=TIdAttachment(Msg.MessageParts.Items[j]).Filename;
            TIdAttachment(Msg.MessageParts.Items[j]).SaveToFile(FAttachPath+FileDate+tempCaption);
          end
          else
          begin
            if Msg.MessageParts.Items[j] is TIdText then
            begin
            end
        end;
    //删除邮箱邮件
        Pop3GetmailInfo.Delete(IntIndex);
      end;
      self.Status.Caption:='接收完毕,(共'+inttostr(self.mailCount)+')封邮件';