1

I'm trying to get all the Deleted Items or Trash folders for all the mail accounts in Outlook. I'm using Outlook Interop in C#, but I can only find the way to get the deleted items folder in the default mail account on MSDN: Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems).

Does anybody know if there is a way that I can get the deleted items folder in every email accounts in Outlook?

Leon Zhou
  • 633
  • 6
  • 20

2 Answers2

3

Loop through the Namespace.Stores collection and call Store.GetDefaultFolder(olFolderDeletedItems) instead of Namespace.GetDefaultFolder.

Alireza Ahmadi
  • 8,579
  • 5
  • 15
  • 42
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • That will only work if they are all on the same outlook profile. If they are on different profiles things will have to get creative. – Bill Dinger Jan 05 '15 at 05:45
  • The OP did not mention anything about multiple profiles, so I assume all the stores are in the same profile. – Dmitry Streblechenko Jan 05 '15 at 05:54
  • I just realised that my component needs to support Outlook 2007, which does not have the GetDefaultFolder method in the Store interface. – Leon Zhou Jan 05 '15 at 07:15
1

In response to the "should work on Outlook 2007" requirement you added in your response to Dmitry's answer, I'd suggest the following approach:

  1. Use a PropertyAccessor to acquire the PR_IPM_WASTEBASKET_ENTRYID ("http://schemas.microsoft.com/mapi/proptag/0x35E30102") of the store
  2. Use PropertyAccessor.BinaryToString to convert it to an EntryID you can use in the COM/interop layer
  3. Use NameSpace.GetItemFromID to access the deleted items folder folder, given it's EntryID and the EntryID of the store.
Paul-Jan
  • 16,746
  • 1
  • 63
  • 95