【发布时间】:2011-03-17 09:11:19
【问题描述】:
如何使用 indy 10 和 delphi 7 接收带有文件附件的电子邮件?
【问题讨论】:
-
您是否正在使用 Indy 组件从 POP3 服务器读取电子邮件并且在读取附件时遇到问题?我在问,否则一个完全有效的答案是 “Indy 与此无关,请某人给你发一些电子邮件”。如果是这样,到目前为止你做了什么?编辑您的问题并显示一些代码。
如何使用 indy 10 和 delphi 7 接收带有文件附件的电子邮件?
【问题讨论】:
这是 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;
【讨论】:
附件作为TIdAttachment 对象存储在TIdMessage.MessageParts 集合中。
【讨论】:
您的代码运行良好,但需要在定义“s”的“begin-end”部分进行更正。如果“文件名”为空程序必须跳过保存。可能你剪断了这条线,“结束”就挂了。
【讨论】: