列出公共文件夹
我正在编写一个程序,用于将联系人从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”的文件夹。 (我甚至不知道该文件夹存在。)
在Office365中调节表示您的代码将只返回邮箱中的前1000个文件夹,因此如果您寻找的内容不在该结果集内,那将是一个原因。我建议你摆脱
FolderView view = new FolderView(Integer.MAX_VALUE);
并将它更改为
文件夹视图视图=新文件夹视图(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后,这将消除需要页面的结果,
嗨格伦, 感谢与SearchFilter意见的文件夹。我将更改代码。 更改为WellKnowFolderName.MsgFolderRoot后,我得到了执行service.findFolders(...)发生的行: 线程“main”中的异常microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException:商店中未找到指定的对象。该进程无法获得正确的属性。 –
这听起来像你没有访问邮箱例如你可能有权访问该特定的文件夹后,但只有当你知道该文件夹的ewsId时才能访问它。您将无法搜索该文件夹,除非您拥有对邮箱其余部分的完全访问权 –
我们找到了解决方案。在Office 365中,联系人文件夹必须设置为对技术用户可见。那么这是否意味着Office 365比办公室2013更受限制? –