uses Outlook2010,
Vcl.ComCtrls;
type
POutlookOrdnerEntryID = ^TOutlookOrdnerEntryID;
TOutlookOrdnerEntryID = String;
procedure FormX.LeseOutlookOrdner(VonFolderID: OlItemType);
var OutlookApplication: TOutlookApplication;
FNameSpace: NameSpace;
procedure LoadFolder(ParentNode: TTreeNode; Folder: Folders);
var
i: Integer;
Node: TTreeNode;
PID: POutlookOrdnerEntryID;
begin
for i:= 1 to Folder.Count do begin
Node:= nil;
if Folder.Item(i).Folders.Count > 0
then begin
if Folder.Item(i).DefaultItemType = VonFolderID then begin
New(PID);
PID^:= Folder.Item(i).EntryID;
end
else PID:= nil;
Node:= OutlookOrdnerTree.Items.AddNode(nil, ParentNode, Folder.Item(i).Name, PID, naAddChild);
end
else if Folder.Item(i).DefaultItemType = VonFolderID
then begin
New(PID);
PID^:= Folder.Item(i).EntryID;
OutlookOrdnerTree.Items.AddNode(nil, ParentNode, Folder.Item(i).Name, PID, naAddChild);
end;
if Assigned(Node) then LoadFolder(Node, Folder.Item(i).Folders);
end;
end;
begin
OutlookApplication:= nil;
try
try
OutlookApplication:= TOutlookApplication.Create(self);
OutlookOrdnerTree.Items.Clear;
FNameSpace:= OutlookApplication.GetNameSpace('
MAPI');
FNameSpace.Logon('', '', false, false);
LoadFolder(nil, FNameSpace.Folders);
except
on E: System.SysUtils.Exception do
begin
raise System.SysUtils.Exception.Create(Format(OutlookFehler1, [E.Message]));
end;
end;
finally
if Assigned(OutlookApplication) then OutlookApplication.Free;
end;
end;