Du musst die Anhand der Anzahl der Dateien dynamisch Speicher holen
Delphi-Quellcode:
var
Attachments,Attachment : PMapiFileDesc;
MailMessage: TMapiMessage;
begin
...
try
with MailMessage do
begin
...
nFileCount := filenamelist.Count;
if nFileCount > 0 then
begin
GetMem(Attachments,SizeOf(TMapiFileDesc) * filenamelist.Count);
Attachment := Attachments;
FOR iCount := 0 TO (filenamelist.Count - 1) do
begin
FileName := filenamelist[iCount];
Attachment.ulReserved := 0;
Attachment.flFlags := 0;
Attachment.nPosition := ULONG($FFFFFFFF);
Attachment.lpszPathName := StrNew(PChar(FileName));
Attachment.lpszFileName := StrNew(PChar(ExtractFileName(FileName)));
Attachment.lpFileType := NIL;
inc(Attachment);
END;
lpFiles := Attachments;
end
else
begin
nFileCount := 0;
lpFiles := nil;
end;
end;
finally
if Assigned(MailMessage.lpFiles) then
FreeMem(MailMessage.lpFiles, MailMessage.nFileCount * sizeof(TMapiFileDesc));
end;
end;