Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips

#121: How can I retrieve items (messages/tasks/etc) from any MS Outlook folder?

Today I want to continue a story about MS Outlook programming.

In previous tip I described how you can retrieve a folder structure and the next task is to read the items from some folder. As you remember each folder have the unique identifier (EntryID). So when you want to read items, you must find this folder by id in MAPI namespace:

  outlook := CreateOleObject('Outlook.Application');
  NameSpace := outlook.GetNameSpace('MAPI');
  Folder := NameSpace.GetFolderByID(EntryID);

After that you must retrieve a type of items in this folder:
intFolderType := Folder.DefaultItemType;
where intFolderType: Integer and can have the one from the next values:

olMailItem $00000000
olAppointmentItem $00000001
olContactItem $00000002
olTaskItem $00000003
olJournalItem $00000004
olNoteItem $00000005
olPostItem $00000006

For example, your folder have an olMailItem type. So the items in your folder are email messages and the next task is to retrieve a list of these messages.

Each folder have an Items collection where all items are placed.
To read a number of messages in folder you must check an Folder.Items.Count.

So the task to navigate by messages is very sample - easy looping.
Important note:
in VBA the first index in collection is 1 instead 0 as in Delphi:

for i := 1 to Folder.Items.Count do
  oiItem := Folder.Items[i];
Now when you have each item in this folder, you can read any property of this item. Note that available property list depends from folder type. For
example, for olMailItem you can read the SenderName, Subject, ReceivedName, ReceivedByName etc but for olAppointmentItem these properties are not
available because this folder type have the ReplyTime, Subject and other properties
Of course, within your looping you can write a standard case-of statement,
check a folder type and read the specific properties for each folder type.
For example:
case intFolderType of
  olMailItem: s := VarToStr(oiItem.SenderName) + oiItem.Subject + oiItem.ReceivedTime + oiItem.ReceivedByName;
  olAppointmentItem: s := oiItem.Subject + oiItem.ReplyTime;
  olContactItem: s := oiItem.FullName + oiItem.Email;
  olTaskItem: s := oiItem.SenderName + oiItem.DueDate + oiItem.PercentComplete;
  olJournalItem: s := oiItem.SenderName;
  olNoteItem: s := oiItem.Subject + oiItem.CreationTime + oiItem.LastModificationTime;
  olPostItem: s := VarToStr(oiItem.SenderName) + oiItem.Subject + oiItem.ReceivedTime;

Of course, you can place each item property into separated variable - I just shown the string concatenation as example. It's very nice to place the items into string grid or listview but it depends from your client application.

Published: May 31, 2001

See also
ExcelFile Viewer
Excel Reader (dll)
Viewer for MS Outlook Messages
Paradox Password Recovery
Paradox to MS Access converter
Word Web-stream
Paradox ActiveX
Excel Web-stream
Paradox Viewer

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.

SMExport/SMImport suites