gpt4 book ai didi

java - 如何使用 EWS Managed API 和 ColdFusion 搜索收件箱?

转载 作者:行者123 更新时间:2023-11-30 07:54:50 25 4
gpt4 key购买 nike

我们正在使用 ColdFusion 2016 并使用 EWS API 连接到交换。我已经设法从以下帖子中获取代码示例,但无法弄清楚如何将 SearchFilter 与 findItems() 方法一起使用。 Why is the get action of cfexchangemail never returning?

service = createObject("Java", "microsoft.exchange.webservices.data.ExchangeService");
service.init();

version = createObject("Java", "microsoft.exchange.webservices.data.ExchangeVersion");
service.init(version.Exchange2010);

credentials = createObject("Java", "microsoft.exchange.webservices.data.WebCredentials");

credentials.init(yourusername, yourpassword);
service.setCredentials(credentials);

uri = createObject("Java", "java.net.URI");
uri.init("outlook webservices url");
service.setUrl(uri);
WellKnownFolderName=createObject("Java","microsoft.exchange.webservices.data.WellKnownFolderName");
result = service.FindItems(service.WellKnownFolderName.Inbox, CreateObject("java", "microsoft.exchange.webservices.data.ItemView").init(100));

for(item in result.getItems(){
// ..loop through each field and store their value
// in query object or something...
}

那么基本上可以将此 Java 代码转换为 Coldfusion 吗?

ItemView view = new ItemView(10);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
view.setPropertySet(new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived));

FindItemsResults<Item> findResults =
service.findItems(WellKnownFolderName.Inbox,
new SearchFilter.SearchFilterCollection(
LogicalOperator.Or, new SearchFilter.ContainsSubstring(ItemSchema.Subject, "EWS"),
new SearchFilter.ContainsSubstring(ItemSchema.Subject, "API")), view);

service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
System.out.println("Total number of items found: " + findResults.getTotalCount());

for (Item item : findResults) {
System.out.println(item.getSubject());
System.out.println(item.getBody());
// Do something with the item.
}

评论更新:

我不知道如何实例化 SearchFilterSearchFilterCollection。我尝试创建一个 searchFilter 对象,但它没有可使用的属性。我一定是错过了什么。

CreateObject("java","microsoft.exchange.webservices.data.Sea‌​rchFilter");

最佳答案

最终的工作结果是:

folderName = createObject("java", "microsoft.exchange.webservices.data.WellKnownFolderName");
itemView = CreateObject("java","microsoft.exchange.webservices.data.ItemView").init(10,0);
folderID = CreateObject("java","microsoft.exchange.webservices.data.FolderId").init(
folderName.Inbox,
mailBox
);
sortDirection = CreateObject("java","microsoft.exchange.webservices.data.SortDirection");
basePropertySet = createObject("java", "microsoft.exchange.webservices.data.BasePropertySet");
propertyset = createObject("java", "microsoft.exchange.webservices.data.PropertySet");
itemSchema = createObject("java", "microsoft.exchange.webservices.data.ItemSchema");
searchFilterCollection = CreateObject("java","microsoft.exchange.webservices.data.SearchFilter$SearchFilterCollection");
logicalOperator = createObject("java", "microsoft.exchange.webservices.data.LogicalOperator");
subString1 = CreateObject("java","microsoft.exchange.webservices.data.SearchFilter$ContainsSubstring").init(
itemSchema.Subject,
"EWS"
);
subString2 = CreateObject("java","microsoft.exchange.webservices.data.SearchFilter$ContainsSubstring").init(
itemSchema.Subject,
"API"
);
searchFilterCollection.add(SubString1);
searchFilterCollection.add(SubString2);
searchFilterCollection.setLogicalOperator(LogicalOperator.Or);
bodyType = createObject("java", "microsoft.exchange.webservices.data.BodyType");
propertyset.add(itemSchema.Subject);
propertyset.add(itemSchema.DateTimeReceived);
propertyset.setBasePropertySet(basePropertySet.IdOnly);
propertyset.setRequestedBodyType(bodyType.HTML);
itemView.getOrderBy().add(itemSchema.DateTimeReceived, sortDirection.Ascending);
itemView.setPropertySet(propertyset);
viewResults = service.findItems(folderID, searchFilterCollection, itemView);

关于java - 如何使用 EWS Managed API 和 ColdFusion 搜索收件箱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43689083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com