unit uMapi;
interface
uses
Mapi;
function SendMailviaMAPI(aSubject, aBody, aFileName,
aSenderName, aSenderEMail,
aRecepientName, aRecepientEMail:
string): integer;
implementation
uses
Forms;
function SendMailviaMAPI(aSubject, aBody, aFileName,
aSenderName, aSenderEMail,
aRecepientName, aRecepientEMail:
string): integer;
var
MapiMessage: TMapiMessage;
lpSender,
lpRecepient: TMapiRecipDesc;
MapiFileDesc: TMapiFileDesc;
begin
FillChar(MapiMessage, SizeOf(MapiMessage), 0);
with MapiMessage
do
begin
if (aSubject <> '
')
then
lpszSubject := PChar(aSubject);
if (aBody <> '
')
then
lpszNoteText := PChar(aBody);
if (aSenderEMail <> '
')
then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (aSenderName = '
')
then
lpSender.lpszName := PChar(aSenderEMail)
else
lpSender.lpszName := PChar(aSenderName);
lpSender.lpszAddress := PChar('
SMTP:' + aSenderEMail);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID :=
nil;
lpOriginator := @lpSender;
end;
if (aRecepientEMail <> '
')
then
begin
lpRecepient.ulRecipClass := MAPI_TO;
if (aRecepientName = '
')
then
lpRecepient.lpszName := PChar(aRecepientEMail)
else
lpRecepient.lpszName := PChar(aRecepientName);
lpRecepient.lpszAddress := PChar('
SMTP:' + aRecepientEMail);
lpRecepient.ulReserved := 0;
lpRecepient.ulEIDSize := 0;
lpRecepient.lpEntryID :=
nil;
nRecipCount := 1;
lpRecips := @lpRecepient;
end
else
lpRecips :=
nil;
if (aFileName = '
')
then
begin
nFileCount := 0;
lpFiles :=
nil;
end
else
begin
FillChar(MapiFileDesc, SizeOf(MapiFileDesc), 0);
MapiFileDesc.nPosition := Cardinal($FFFFFFFF);
MapiFileDesc.lpszPathName := PChar(aFileName);
nFileCount := 1;
lpFiles := @MapiFileDesc;
end;
end;
// with MapiMessage
Result := MAPISendMail(0, Application.Handle, MapiMessage, MAPI_DIALOG
or MAPI_LOGON_UI
{or MAPI_NEW_SESSION}, 0);
if (Result = MAPI_USER_ABORT)
then
Result := SUCCESS_SUCCESS;
end;
// SendMailviaMAPI
end.