uses Mapi;
procedure TForm1.Button1Click(Sender: TObject);
var Err: Cardinal;
SessionID: LHANDLE;
MessID: AnsiChar;
pMsg: PMapiMessage;
i: Integer;
begin
Err := MapiLogOn(
Handle, '
', '
', MAPI_EXPLICIT_PROFILE, 0, @SessionID);
i := 1;
Err := MapiFindNext(SessionID,
Handle, '
', '
', MAPI_UNREAD_ONLY, 0, @MessID);
while Err = SUCCESS_SUCCESS
do
begin
Err := MapiReadMail(SessionID, 0, @MessID, MAPI_UNREAD_ONLY
or MAPI_PEEK, 0, pMsg);
// <- ab hier simmt die Session-ID nicht mehr
if Err = SUCCESS_SUCCESS
then begin
StringGrid1.Cells[0,i] := MessID;
StringGrid1.Cells[1,i] := pMsg^.lpOriginator^.lpszName + '
(' + pMsg^.lpOriginator^.lpszAddress + '
)';
StringGrid1.Cells[2,i] := pMsg^.lpszSubject;
StringGrid1.Cells[3,i] := pMsg^.lpszDateReceived;
Inc(i);
end;
Err := MapiFreeBuffer(pMsg);
Err := MapiFindNext(SessionID, 0,
nil, @MessID, MAPI_UNREAD_ONLY, 0, @MessID);
end;
Err := MapiLogOff(SessionID, 0, MAPI_LOGOFF_SHARED, 0);
end;