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

时间:2011-03-17 09:11:20

标签: delphi indy10

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

3 个答案:

答案 0 :(得分:4)

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

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;

答案 1 :(得分:3)

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

答案 2 :(得分:0)

您的代码工作正常,但需要在“s”定义的“开始 - 结束”部分进行更正。如果“FileName”为空,则程序必须跳过保存。可能你切断了这条线并且“结束”正在悬挂。