1

I have a routine to get specific folders from an Outlook store:

// Property Tag of SentFolder
string propertyName = "http://schemas.microsoft.com/mapi/proptag/0x35E40102";

Outlook.Folders folders = store.GetRootFolder().Folders;
object entry = propertyAccesor.GetProperty(propertyName);
defaultFolderEntryID = propertyAccesor.BinaryToString(entry);

if (!string.IsNullOrEmpty(defaultFolderEntryID))
{
   foreach (Outlook.Folder defaultFolder in folders)
   {
      if (defaultFolder.EntryID == defaultFolderEntryID)
      {
         folder = defaultFolder;
         break;
      }
      else
         Marshal.ReleaseComObject(defaultFolder);   
   }
}

Marshal.ReleaseComObject(folders);
Marshal.ReleaseComObject(store);

I have the property tag of the Sent Mail, Outbox and Deleted Items, but I cannot find the property tag of the Junk (or Spam) folder. Any body knows what is the value if it exists?

Thanks.-

Joe Almore
  • 4,036
  • 9
  • 52
  • 77

1 Answers1

2

Why not use Namespace/Store.GetDefaultFolder(olFolderJunk)? Unless of course you are trying to open the Junk Mail folder of a delegate mailbox (you can use Store.GetDefaultFolder in Outlook 2010 or newer).

On the MAPI level, the entry id is stored in the PR_ADDITIONAL_REN_ENTRYIDS (0x36D81102) multivalued binary property; it is stored with the index of 4 (0 based). You can see it in OutlookSpy (I am its author - click IMAPIFolder button when the Inbox folder is selected).

Since Outlook 2007 does not expose the Store object (so that you can use Store.GetDefaultFolder), you can use Redemption (I am also its author - any version of Outlook) - it exposes RDOStore.GetDefaultFolder method in all versions of Outlook.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks for your answer. Yes, `Store.GetDefaultFolder()` will work but for Outlook 2010 and newer as you said. I tried the `PR_ADDITIONAL_REN_ENTRYIDS` but it fails when executing `propertyAccesor.BinaryToString(propertyAccesor.GetProperty(propertyName))` saying `Type Mismatch. You must supply a binary value for conversion`. In fact, the object returned by `propertyAccesor.GetProperty(propertyName)` contains different array size from the other folders. – Joe Almore Sep 23 '14 at 21:04
  • Got it! As you say it is stored in the fourth index of the array, so changing `defaultFolderEntryID = propertyAccesor.BinaryToString(entry);` to `defaultFolderEntryID = propertyAccesor.BinaryToString(entry[4]);` solved the issue and the Junk folder is retrieved. Thanks. – Joe Almore Sep 23 '14 at 21:26