I am programming an Outlook Add-in and need to determine whether a selected email is from Inbox or Sent Items so that I can tag the email with folder=”Inbox” or “Sent” when I save it in my database.
I understand that I can compare the folder name to Inbox or Sent Items and determine the folder, however, how do I determine when the email selected is sitting in one of the sub-folders in the inbox. Is there a FolderType property to check whether the selected email’s folder is inbox or sent (similar to identifying an item type with OlItemType)?
You need to look at the
MailItem.Parentand cast it to aOutlook.Folder. Once you have theFolder, you can access the display name viaFolder.Name. If you want to determine whether the selected item is a subfolder ofInbox, you would need to recursively call up theParenttree untilParentis null to find the root parent folder.You should obviously add error handling and object disposal to this sample code.