Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
How do you search an inbox using the EWS Managed API with ColdFusion?

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.Sea‌​rchFilter");
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The final working result was:

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);
over 4 years ago · Santiago Trujillo Relatório

0

(Not an a full answer, but too long for comments)

No wonder... that is a lot of nesting. I do not have that lib installed, but if it were me I would start by breaking it down into separate statements, one new object per line. Start with the innermost constructor:

new SearchFilter.ContainsSubstring(
          ItemSchema.Subject
        , "API"
    )

You will need to create an instance of ItemSchema first, to have access the Subject property. Looking at the C# docs (no javadocs available) the path should be something like this:

ItemSchema = createObject("java", "microsoft.exchange.webservices.data.ItemSchema");

After that move on to creating the SearchFilter. Notice the period . in the class name? The keyword new followed by a class name, containing a period, usually means it is an inner class. Inner classes require a special syntax, ie ParentClass$InnerClass. Something like this should work:

APISubString = CreateObject("java","microsoft.exchange.webservices.data.SearchFilter$ContainsSubstring");
writeDump(APISubString );

If it works, add init() to initialize the object:

  APISubString = CreateObject("java","microsoft.exchange.webservices.data.SearchFilter.ContainsSubstring").init(ItemSchema.Subject, "API");

Then move to the next innermost object:

new SearchFilter.ContainsSubstring(
           ItemSchema.Subject
          , "EWS"
    )

and lather, rinse, repeat for the remaining objects:

// ItemSchema.Subject is a static value and can be reused
EWSSubString = CreateObject("java","microsoft.exchange.webservices.data.SearchFilter.ContainsSubstring").init(ItemSchema.Subject, "EWS");
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda