Is there a way to exclusively identify email-enabled public folders using Microsoft.Office.Interop.Outlook? EWS or PowerShell should not be used. The program should run on the workstation and utilize the installed Outlook.
Once I've found an email-enabled public folder, I should list the emails contained within it.
So far, I'm encountering difficulties. For instance, I have the following method:
// Recursive method for listing the email addresses of email-enabled public folders
static void ListPublicFolders(Outlook.Folder? folder, string indent)
{
if (folder != null)
{
foreach (object obj in folder.Folders)
{
if (obj is Outlook.Folder)
{
Outlook.Folder? subFolder = obj as Outlook.Folder;
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
{
Outlook.MAPIFolder? parentFolder = subFolder.Parent as Outlook.MAPIFolder;
string parentName = parentFolder != null ? parentFolder.Name : "Parent folder not found";
Console.WriteLine($"{indent}- {subFolder.Name}: {parentName}");
if (parentFolder != null)
{
Marshal.ReleaseComObject(parentFolder);
}
}
ListPublicFolders(subFolder, indent + " ");
if (subFolder != null)
{
Marshal.ReleaseComObject(subFolder);
}
}
}
}
}
The query
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
fails because subFolder.DefaultItemType
returns the value Outlook.OlItemType.olPostItem
, even though the public folder was set up as an email-enabled folder in Exchange.
Specifically, this is in Microsoft 365. In the Exchange admin center, when creating the folder, I explicitly checked the box for "Email-enabled." This action resulted in two additional options: "Delegation" and "Email properties." In "Email properties," I can specify an alias and a display name. By default, both fields are set to "Orders." Now, I expect the public folder to be email-enabled, with the email address orders@domain.tld.
I don't understand why Outlook is treating the folder incorrectly (I can only create posts and not send emails).
Perhaps someone can help me figure this out.
Thank you and best regards,
René