We are using ColdFusion 2016 and are using the EWS API to connect to exchange. I have managed to get the code sample from the following post working but am not able to figure out how to use the SearchFilter with the findItems() method. 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...
}
So basically is it possible to translate this Java code to 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.
}
Update from comments:
I can't figure out how to instantiate the SearchFilter
or SearchFilterCollection
. I tried creating a searchFilter object, but it does not have the properties to work with. I must be must be missing something.
CreateObject("java","microsoft.exchange.webservices.data.SearchFilter");