function Create_Email(eHandle: Hwnd; eReceiver, eSubject, eBody, eFiles:
String): integer;
const
MaxFiles = 255;
type
TAttachAccessArray =
array [0 .. MaxFiles]
of TMapiFileDesc;
var
Mapi_Message: TMapiMessage;
Receip : TMapiRecipDesc;
Attachments : TAttachAccessArray;
i : integer;
Mapi_Session : Cardinal;
WndList : Pointer;
FileList : TStringList;
FileName :
array [0 .. MaxFiles]
of AnsiString;
begin
result := MapiLogon(eHandle,
Nil,
Nil, Mapi_Logon_Ui
or Mapi_New_Session, 0, @Mapi_Session);
if result = Success_Success
then
begin
FillChar(Mapi_Message, SizeOf(Mapi_Message), #0);
FillChar(Receip, SizeOf(Receip), #0);
if eReceiver <> '
'
then
begin
Receip.ulReserved := 0;
Receip.ulRecipClass := Mapi_To;
Receip.lpszName := PAnsiChar(AnsiString(eReceiver));
Receip.lpszAddress := PAnsiChar('
SMTP:' + AnsiString(eReceiver));
Receip.ulEIDSize := 0;
Mapi_Message.nRecipCount := 1;
Mapi_Message.lpRecips := @Receip;
end;
FileList := TStringList.Create;
try
FileList.Text := eFiles;
if FileList.Count > 0
then
begin
if FileList.Count > MaxFiles
then
begin
result := -MaxInt;
exit;
end;
for i := 0
to FileList.Count - 1
do
begin
FileName[i] := AnsiString(FileList[i])+#0;
Attachments[i].ulReserved := 0;
Attachments[i].flFlags := 0;
Attachments[i].nPosition := ULONG($FFFFFFFF);
Attachments[i].lpszPathName := PAnsiChar(FileName[i]);
Attachments[i].lpszFileName :=
Nil;
Attachments[i].lpFileType :=
Nil;
end;
Mapi_Message.nFileCount := FileList.Count;
Mapi_Message.lpFiles := @Attachments;
end;
finally
FileList.Free;
end;
if eSubject <> '
'
then
Mapi_Message.lpszSubject := PAnsiChar(AnsiString(eSubject));
if eBody <> '
'
then
Mapi_Message.lpszNoteText := PAnsiChar(AnsiString(eBody));
WndList := DisableTaskWindows(0);
try
result := MapiSendMail(Mapi_Session, eHandle, Mapi_Message, Mapi_Dialog, 0);
// original!
finally
EnableTaskWindows(WndList);
end;
MapiLogOff(Mapi_Session, eHandle, 0, 0);
end
else
result := -result;
end;