【问题标题】:Listing public folders列出公用文件夹
【发布时间】:2017-04-12 13:35:38
【问题描述】:

我正在编写一个程序,用于将联系人从 ERP 系统导入 Outlook。不同的电子邮件将收到来自 ERP 的不同联系人列表。这里的想法是,在每封电子邮件中,我都有一个技术用户可以访问的公共联系人文件夹。技术用户可以将联系人写入此文件夹。这是搜索文件夹的代码:

protected FolderId findFolderId(String folderDisplayName, String userEmail) throws Exception {
    Mailbox userMailbox = new Mailbox(userEmail);
    FolderId contactRootFolder = new FolderId(WellKnownFolderName.Root, userMailbox);

    FolderId result = null;
    FolderView view = new FolderView(Integer.MAX_VALUE);
    view.setPropertySet(new PropertySet(BasePropertySet.IdOnly, FolderSchema.DisplayName));
    view.setTraversal(FolderTraversal.Deep);
    FindFoldersResults findFolderResults = this.service.findFolders(contactRootFolder, view);
    //find specific folder
    for (Folder f : findFolderResults) {
        if (folderDisplayName.equals(f.getDisplayName())) {
            result = f.getId();
        }
    }

    return result;
}

服务对象的创建如下:

this.service = new ExchangeService();
    ExchangeCredentials credentials = new WebCredentials(userName, passWord);
    this.service.setCredentials(credentials);

    try {
        this.service.setUrl(new URI(URL));
    } catch (URISyntaxException e) {
        LOGGER.error(e);
    }

其中 URL 是 Exchange 服务器的端点(对于 Office 365,它是 https://outlook.office365.com/EWS/Exchange.asmx)。

代码适用于 Office 2010,我从该文件夹中获取 Id,连接到它并保存联系人。迁移到 Office 365 后,我们找不到公用文件夹。它只能找到一个名为“PeoplePublicData”的文件夹。 (我什至不知道那个文件夹存在。)

【问题讨论】:

    标签: java outlook office365 exchangewebservices


    【解决方案1】:

    Office365 中的限制意味着您的代码将仅返回邮箱中的前 1000 个文件夹,因此如果您要查找的内容不在该结果集中,那将是一个原因。我建议你摆脱

    FolderView 视图 = new FolderView(Integer.MAX_VALUE);

    并将其更改为

    FolderView 视图 = 新的 FolderView(1000);

    然后将结果分页https://msdn.microsoft.com/en-us/library/office/dn592093(v=exchg.150).aspx,这将允许您获取邮箱中的所有文件夹。此外,除非您在邮箱的 Non_IPM_Subtree 中查找某些内容,否则请使用 MsgFolderRoot 开始搜索,例如

    FolderId contactRootFolder = new FolderId(WellKnownFolderName.MsgFolderRoot, userMailbox);

    这将减少返回的文件夹数量。

    另外,你为什么不使用 SearchFilter 来搜索你要搜索的文件夹,例如 https://msdn.microsoft.com/en-us/library/office/dd633627(v=exchg.80).aspx 这将消除对结果进行分页的需要,

    【讨论】:

    • 您好 Glen,感谢您对 SearchFilter 的建议。我将更改代码。更改为 WellKnowFolderName.MsgFolderRoot 后,我​​在发生 service.findFolders(...) 的行出现异常:线程“main”中的异常 microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: The specified在商店中找不到对象。,该过程未能获得正确的属性。
    • 听起来您无权访问邮箱,例如,您之后可能有权访问该特定文件夹,但只有知道文件夹的 ewsId 才能访问它。除非您对邮箱的其余部分拥有完全访问权限,否则您将无法搜索该文件夹
    • 我们找到了解决方案。在 Office 365 中,联系人文件夹必须设置为对技术用户可见。那么这是否意味着 office 365 比 office 2013 更受限制?
    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    • 2013-03-02
    • 2012-03-23
    • 2019-06-23
    • 2016-04-14
    • 2013-10-10
    相关资源
    最近更新 更多