【问题标题】:How to receive emails using indy 10 and delphi 7 with the file attachment?如何使用 indy 10 和 delphi 7 接收带有文件附件的电子邮件?
【发布时间】:2011-03-17 09:11:19
【问题描述】:

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

【问题讨论】:

  • 您是否正在使用 Indy 组件从 POP3 服务器读取电子邮件并且在读取附件时遇到问题?我在问,否则一个完全有效的答案是 “Indy 与此无关,请某人给你发一些电子邮件”。如果是这样,到目前为止你做了什么?编辑您的问题并显示一些代码。

标签: delphi indy10


【解决方案1】:

这是 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;

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 能否请您提供完整的代码,我可以在其中获取邮件和附件文件或任何工作或测试的示例,这将是非常有用的提前谢谢。
    • kapil - 这里的人希望你尝试一些东西,然后告诉我们你卡在哪里了。你对我来说听起来很懒惰。
    【解决方案3】:

    您的代码运行良好,但需要在定义“s”的“begin-end”部分进行更正。如果“文件名”为空程序必须跳过保存。可能你剪断了这条线,“结束”就挂了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2010-12-20
      • 2021-03-06
      • 1970-01-01
      相关资源
      最近更新 更多