I need to iterate through the MailItem items within a Selection and read their EntryID and StoreID values in order to be able to retrieve the mail items again later (for background processing through Redemption). Is there a way of retrieving the StoreID for a MailItem directly?
I know that it may be retrieved through the StoreID property of its parent Folder; however, this seems quite inefficient, since it must instantiate (and release) the COM object for the parent folder for each item. Is there a more efficient way to achieve this?
Edit: I cannot use the Selection.Parent property since it was only introduced in Outlook 2007, and I need to support Outlook 2003. Additionally, Sue Mosher states:
The
Parentobject of aSelectionwould be anExplorer, so you could useSelection.Parent.CurrentFolder.Store.
However, when one performs a search across “All Outlook Items”, it seems that CurrentFolder would always point to a search folder within the main store, which is typically the Exchange mailbox:
\\Mailbox - <username>\search folders\All Outlook Items
Since the search may match items in other stores, the CurrentFolder.Store would not necessarily correspond to the store of the selected items, making this approach unreliable.
Instead of getting the parent for each item, could you get the parent once by using
Selection.Parent?