Hi there... here is some code that I use that works ok.
Regards
Colin
----------------
function SendMAPIMessage(const ToName, ToAddress, Subject, theMessage :
string; Attachments : TStrings) : integer;
{Notes: 'ToName' is the name or alias of the recipient. This name might be
resolved
to an address if the address field is blank.
'ToAddress' is the actual address of the recipient. The address
field can
be blank in which case the 'ToName' field will try to be resolved
to
a legal address by looking through the address book. If the name
cannot be
resolved the message is not sent and the error code is returned.
If the address field is not blank, the message will be sent even
if the
address is invalid, in this case an undeliverable error message
will be
sent to the user from the mail administrator to inform them that
the
message did not go through. The address field must be in a
specific format
depending on how the message is to be delivered. The address
formats
depend on the server provider. Some examples are shown below:
MS mail format: 'MS:/Network/Postoffice/Mailbox'
MS mail example: 'MS:Windows/Server/Fred' (look at the
addresses in the
address book to see the network, postoffice and mailbox
names)
SMTP mail format: 'SMTP:name@address'
SMTP mail example: 'SMTP:[EMAIL PROTECTED]'
Fax format: 'FAX:fax number'
Fax example: 'FAX:8582001'}
type
TMapiFileDescs = array[0..100000] of TMapiFileDesc; {Some arbittry size,
this never gets created, only
a pointer to it is used, the pointer usually points to far less than
this size.}
PMapiFileDescs = ^TMapiFileDescs;
var
i : integer;
RecieverDesc : TMapiRecipDesc;
MapiMessage : TMapiMessage;
PtrMapiFileDescs : PMapiFileDescs;
hSession : THandle;
begin
PtrMapiFileDescs := nil;
with RecieverDesc do begin
ulReserved := 0; { Reserved for future
}
ulRecipClass := MAPI_TO; { Recipient class: MAPI_TO, MAPI_CC,
MAPI_BCC, MAPI_ORIG }
lpszName := PChar(ToName); { Recipient
}
lpszAddress := PChar(ToAddress); { Recipient address
}
ulEIDSize := 0; { Count in bytes of size of
ID }
lpEntryID := nil; { System-specific recipient
ence }
end;
if Attachments.Count > 0 then begin
GetMem(PtrMapiFileDescs, Attachments.Count * SizeOf(MapiFileDesc));
FillChar(PtrMapiFileDescs^, Attachments.Count * SizeOf(MapiFileDesc),
0);
//PtrMapiFileDescs := AllocMem(Attachments.Count *
SizeOf(MapiFileDesc));
for i := 0 to Attachments.Count - 1 do
with PtrMapiFileDescs^[i] do begin
nPosition := $FFFFFFFF;
lpszPathName := StrNew(PChar(Attachments[i]));;
end;
end;
with MapiMessage do begin
ulReserved := 0; { Reserved for future use (M.B.
0) }
lpszSubject := PChar(Subject); { Message
}
lpszNoteText := PChar(theMessage); { Message
}
lpszMessageType := nil; { Message
}
lpszDateReceived := nil; { in YYYY/MM/DD HH:MM
}
lpszConversationID := nil; { conversation thread
}
flFlags := 0; { unread,return
}
lpOriginator := nil; { Originator descriptor (unused
for send)}
nRecipCount := 1; { Number of
}
lpRecips := @RecieverDesc; { Recipient
}
nFileCount := Attachments.Count; { # of file
}
lpFiles := @PtrMapiFileDescs^ { Attachment descriptors (the @
^ just stops the compiler error }
end; { We could have used
PMapiFileDesc(PtrMapiFileDescs) instead }
{if we logon first, this will allow it to work hands free if the MAPI
client is not loaded}
result := MAPILogon(0, PChar(MapiProfileStr), '', MAPI_LOGON_UI, 0,
@hSession);
if result = SUCCESS_SUCCESS then
result := MAPISendMail(hSession, 0, MapiMessage, MAPI_LOGON_UI, 0);
{Free all the allocated memory}
if Attachments.Count > 0 then begin
for i := 0 to Attachments.Count - 1 do
StrDispose(PtrMapiFileDescs^[i].lpszPathName);
FreeMem(PtrMapiFileDescs);
end;
end;
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz