Retrieving Outlook Inbox and Sent Items Folders in Delphi Using OLE

What is the best way to extract Outlook folders from Delphi? Ideally, I would like to get the inbox and any other folders inside it. I do not require the headers / emails to be just folder names.

Delphi BDS 2006

+3
source share
1 answer

See here for the Outlook object model. Below are the names of the folders in your inbox:

procedure TForm1.Button1Click(Sender: TObject);
var
  Outlook, oNameSpace, Inbox: OleVariant;
  i: Integer;
begin
  try
    Outlook := GetActiveOleObject('Outlook.Application');
  except
    Outlook := CreateOleObject('Outlook.Application');
  end;
  oNameSpace := Outlook.GetNamespace('MAPI');
  oNameSpace.Logon('', '', False, False);   // not sure if this is necessary
  Inbox := oNameSpace.GetDefaultFolder(olFolderInbox);
  for i := 1 to Inbox.Folders.Count do
    ShowMessage(Inbox.Folders[i].Name);
end;
+7
source

All Articles