var MessID: AnsiChar;
pMsg: PMapiMessage;
Err: Cardinal;
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
Session: LHANDLE;
begin
Err := MapiLogOn(
Handle, '
', '
', MAPI_EXPLICIT_PROFILE, 0, @Session);
if Err <> SUCCESS_SUCCESS
then begin
ShowMessage('
Verbindung konnte nicht hergestellt werden! ' + IntToStr(Err));
Exit;
end;
i := 1;
Err := MapiFindNext(Session,
Handle, '
', '
', MAPI_UNREAD_ONLY, 0, @MessID);
while Err = SUCCESS_SUCCESS
do
begin
Err := MapiReadMail(Session, 0, @MessID, MAPI_PEEK, 0, pMsg);
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);
Application.ProcessMessages;
end;
Err := MapiFindNext(Session, 0,
nil, @MessID, MAPI_UNREAD_ONLY, 0, @MessID);
end;
MapiFreeBuffer(pMsg);
MapiLogOff(Session, 0, MAPI_LOGOFF_SHARED, 0);
StringGrid1.RowCount := Max(i, 2);
end;