[英]How to receive emails using indy 10 and delphi 7 with the file attachment?
如何使用帶文件附件的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”定義的“開始 - 結束”部分進行更正。 如果“FileName”為空,則程序必須跳過保存。 可能你切斷了這條線並且“結束”正在懸掛。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.