如何使用带文件附件的indy 10和delphi 7接收电子邮件?

kap*_*rma 5 delphi indy10

如何使用带文件附件的indy 10和delphi 7接收电子邮件?

No'*_*man 5

这是有效的 Indy 10 代码。“文件”是一个字符串列表,其中包含已下载的附件列表 - 我对附件感兴趣,而不是字母本身。

with IdPop31 do
begin
  ConnectTimeout := 5000;
  Connect;
  try
    files.Clear;
    for i := 1 to checkmessages do
    begin
      msg.clear;
      flag := false;
      if retrieve (i, msg) then
      begin
        for j := 0 to msg.MessageParts.Count-1 do
        begin
          if msg.MessageParts[j] is TIdAttachment then
          begin
            with TIdAttachment(msg.MessageParts[j]) do
            begin
              s := IncludeTrailingPathDelimiter(mydir) + ExtractFileName(FileName);
              log ('Downloaded ' + s);
              if not FileExists(s) then
              begin
                SaveToFile(s);
                files.Add(s);
              end;
             end;
            end;
            flag := true;
          end;
        end;
      end;
      if flag then Delete(i);  // remove the email from the server
    end;
  finally
    Disconnect;
  end
end;
Run Code Online (Sandbox Code Playgroud)


Rem*_*eau 4

TIdAttachment附件作为对象存储在TIdMessage.MessageParts集合中。