outlookoutlook-addinoutlook-2007mapi

MAPI Property to get Junk Folder in Outlook 2007


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.-


Solution

  • 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.