fabianse Guest
|
Posted: Tue Dec 07, 2004 3:15 pm Post subject: Re: Indy 9.0 TIdPOP3 - corrupted attachments |
|
|
Here you have a procedure to read multi part mails, with Indy 9
components, access each part, and save attachments to file. This
procedure deletes the file if exists.
Before call de procedure, create two components, TIdPOP3 and
TIdMessage, and set de properties of TIdPOP3, host, username, password,
to a valid pop3 account.
Regards
procedure ReadmailAndSaveAttachments(IdPOP31: TIdPop3; IdMessage1:
TIdMessage);
var pop3mailcounttotalI : integer;
var I : integer;
var J : integer;
begin
IdPOP31.Connect;
pop3mailcounttotalI := IdPOP31.CheckMessages;
// browse all mails
for I := 1 to pop3mailcounttotalI do
begin
// get current mail
if IdPOP31.Retrieve( I, IdMessage1 ) then
begin
// browse mail parts
for J := 0 to Pred( IdMessage1.MessageParts.Count ) do
begin
// if the part is an attachment
if ( IdMessage1.MessageParts.Items[ J ] is TIdAttachment) then
begin
// save the attachment to file
if fileexists(TIdAttachment(IdMessage1.MessageParts.Items[J]
).Filename)
then deletefile(TIdAttachment(IdMessage1.MessageParts.Items[J]
).Filename);
TIdAttachment(IdMessage1.MessageParts.Items[J]
).SaveToFile(TIdAttachment(IdMessage1.MessageParts.Items[J]
).Filename);
end;
end;
// delete the message
IdPOP31.Delete(I);
end
else
begin
ShowMessage( 'Could not be retrieved' );
end;
end;
IdPOP31.Disconnect;
end;
|
|