Scalabium Software |
|
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:
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. So the task to navigate by messages is very sample - easy
looping. for i := 1 to Folder.Items.Count do begin oiItem := Folder.Items[i]; ... end; 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; end; 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.
|
Copyright© 1998-2024, Scalabium
Software. All rights reserved. |