如何通过EWS从Exchange 2013中的一个公用文件夹邮箱中获取公用文件夹 [英] How to get public folders from one Public folder mailbox in Exchange 2013 via EWS

查看:157
本文介绍了如何通过EWS从Exchange 2013中的一个公用文件夹邮箱中获取公用文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下powershell命令检索存储在特定公用文件夹邮箱中的公用文件夹:

I can retrieve public folders stored in specific Public folder mailbox using this powershell command:

Get-PublicFolder –GetChildren | Where { $ _.ContentMailboxName –eq "PFMailbox1" }

(但是我不想使用远程PowerShell)

(But I don't want to use remote PowerShell)

我无法使用EWS做到这一点.

I'm not able to do this using EWS.

我的第一个想法是获取所有公用文件夹,然后根据公用文件夹邮箱对其进行排序.

My first idea was to get all public folders and then sort them according Public folder mailboxes.

但是可能没有包含公用文件夹邮箱名称的Extended MAPI属性(类似于ContentMailboxName powershell属性).

But there is probably no Extended MAPI property which contains public folder mailbox name (similar to ContentMailboxName powershell property).

所以我尝试了这个: 具有委托权限的EWS

So I tried this: EWS with delegate access

var mailbox = new Mailbox("PFMailbox1@MyDomain.local"); 
// PFMailbox1 is Public Folder mailbox with Pubclic folders
FolderId folderId = new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox);
Folder rootfolder = Folder.Bind(service, folderId);

(WellKnownFolderName属性也已通过.Root和PublicFolderRoot进行了测试)

(WellKnownFolderName property was tested with .Root and PublicFolderRoot too)

但是我总是会出错:

请求失败.远程服务器返回错误:(503)服务器 不可用."或类型的未处理异常 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' 发生在Microsoft.Exchange.WebServices.dll中"

"The request failed. The remote server returned an error: (503) Server Unavailable." or "An unhandled exception of type 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' occurred in Microsoft.Exchange.WebServices.dll"

当我尝试模仿时

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, impUser);
// impUser=PFMailbox1@MyDomain.local
Folder rootfolder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot );

我收到错误消息:

"该帐户无权模拟所请求的 用户."

"The account does not have permission to impersonate the requested user."

用户Administrator和PFMailbox1的所有邮箱权限都设置为完全访问权限. 我正在使用最新的Exchange2013 dll.

All mailbox permission for user Administrator and PFMailbox1 are set to full access. I'm using latest Exchange2013 dll's.

第二个问题是如何创建根公用文件夹并将其保存到所需的公用文件夹邮箱?

EWS方法Folder.Save(FolderId)只有一个参数,如果我使用FolderId = PublicFolderRoot->所有文件夹都将保存到MasterHierarchy Public Folder Mailbox(首次创建的邮箱)中.

EWS method Folder.Save(FolderId) has only one parameter and if I use FolderId = PublicFolderRoot -> all folders will be saved into MasterHierarchy Public Folder Mailbox (mailbox which was first created).

我知道的唯一解决方案是使用Remote Power Shell为每个公用文件夹邮箱创建第一级(根)文件夹.

The only solution I know is to create first level (root) folders using Remote Power Shell for every Public Folder Mailbox.

New-PublicFolder "Folder1" -Mailbox "PFMailbox1"
New-PublicFolder "Folder2" -Mailbox "PFMailbox2"

,然后在第二(第三,..)文件夹级别上,我可以使用Folder.Save(FolderID). 但是如何使用EWS做到这一点?

and then on second (third,..) folder level I can use Folder.Save(FolderID). But how to do it using EWS ?

推荐答案

我找到了可能的解决方案.

I found a possible solution.

Exchange 2013的公用文件夹中有一个未命名的扩展EWS属性"0x6656"(我使用OutlookSpy-选定的公用文件夹邮箱,单击EMAPIFolder).

There is an unnamed extended EWS property "0x6656" in public folder in Exchange 2013 (I used OutlookSpy - selected public folder mailbox, click on EMAPIFolder).

例如有4e1f53e4-0f2d-46eb-873f-b4857d9d395a@myDomain.local

一个公用文件夹邮箱中的每个文件夹的值都相同. GUID(在@之前)是ExchangeMailboxGuid-可以与Active Directory中的公用文件夹邮箱一起读取,然后将公用文件夹与邮箱配对.

The value is the same for every folder in one public folder mailbox. The GUID (before @) is the ExchangeMailboxGuid - this can be read together with public folder mailbox from Active Directory and then pair public folders with mailbox.

问题是我无法使用托管EWS读取此属性(我无法读取任何未命名的扩展属性).我使用了以下定义:

The problem is that I was not able to read this property using managed EWS (I'm not able to read any unnamed Extended properties). I used this definition:

var ExchangeMailboxGuid = new ExtendedPropertyDefinition(0x6656, MapiPropertyType.String);

也许我可以尝试非托管的EWS,但是它更加复杂.

Maybe I can try unmanaged EWS, but it is more complicated.

作为临时解决方案,我结合了EWS和远程PowerShell.这是我的伪代码:

As a temporary solution I combined EWS and remote PowerShell. Here is my pseudocode:

if (folderId == null)   // It is root public folder
{
    var mailboxGuid = GetMailboxId();
    // public folder root
    var ewsFolderId = EwsAdapter.GetPublicFolderId(folderId);
    // get all root public folders from all public folder mailboxes
    var tempFindFolderResults = FindFolders(ewsFolderId);

    var powerShellConnection = new powerShellConnection(ConnectionConfiguration);
    // get all root public folders with info which mailbox is owner
    var PublicFolderMailboxes = powerShellConnection.GetPublicFolders();

    foreach (var publicFolderMailbox in PublicFolderMailboxes)
    {
        if (publicFolderMailbox.Attributes["ExchangeMailboxGuid"].Value == mailboxGuid)
        {
            foreach (var tempFindFolderResult in tempFindFolderResults)
            {
                if (tempFindFolderResult.DisplayName == publicFolderMailbox.Attributes["Name"].Value)
                {
                    // add only folder from selected public folder mailbox
                    findFolderResults.Add(tempFindFolderResult);
                }
            }
        }
    }
}
else  // it is public subfolder - standard handling
{
    var ewsFolderId = EwsAdapterHelper.GetPublicFolderId(folderId);
    findFolderResults = FindFolders(ewsFolderId);
}

这是我在方法GetPublicFolders中使用的PowerShell命令:

Here's the PowerShell command I use in the method GetPublicFolders:

Get-PublicFolder -GetChildren

:我认为EWS不完全支持Exchange 2013公用文件夹-

I think EWS doesn't fully support Exchange 2013 Public Folders -

  1. 如何从任何公用文件夹邮箱"中获取公用文件夹和
  2. 将根目录下的公用文件夹保存到任何公用文件夹邮箱"(不仅是主公用文件夹邮箱).

这篇关于如何通过EWS从Exchange 2013中的一个公用文件夹邮箱中获取公用文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆