EWS API and ColdFusion: How to reference returned values

こ雲淡風輕ζ 提交于 2019-12-24 08:49:13

问题


I am having difficulty working with complex arrays and could use some help. I am working with the EWS API to integrate mail functions with Exchange 2010 and CF. The code below connects to a mailbox that the primary account has delegated authority to. I want to return a list of messages in the inbox and work with the values that EWS returns (subject line, body, from, to, etc).

I have not worked with complex arrays like this before, so I'm confused about how to reference the values returned, specifically within the getItems() method that is returned in FindItemsResults. I have looked a Java examples that do this same task, but I'm having trouble getting my mind wrapped around how this translates to CF. CFDump shows that I am getting information back, so I'm confident that the connection is working as intended. I just need to get at the data and don't know how to do it.

Thanks in advance for any help.

<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeService" name="service">
<cfset service.init()>

<cfobject type="Java" class="microsoft.exchange.webservices.data.WebCredentials" name="credentials">
<cfset credentials.init("username","password", "domain")>
<cfset service.setCredentials(credentials) />

<cfset service.AutodiscoverUrl("email@domain.com")>

<cfobject type="java" class="microsoft.exchange.webservices.data.WellKnownFolderName" name="WellKnownFolderName">

<cfset ViewResults = service.findItems(CreateObject("java","microsoft.exchange.webservices.data.FolderId").init(WellKnownFolderName.Inbox, 
CreateObject("java","microsoft.exchange.webservices.data.Mailbox").init("othermail@domain.com","SMTP")),
CreateObject("java","microsoft.exchange.webservices.data.ItemView").init(3)) />

<cfdump var="#ViewResults#">

<cfdump var="#ViewResults.getItems()#">


回答1:


(From the comments ...)

So it looks like ViewResults.getItems() returns an array of EmailMessage objects. EmailMessage has a bunch of methods. Some return simple values (boolean, string, ..) and others like getFrom() return complex objects.

Try doing an array loop and inside it output one of the simple properties like: getIsRead() or getReferences(). ie

 <cfloop array="#itemsArray#" index="message"> 
     <cfdump var="#message.getIsRead()#" label="getIsRead()">
     <cfdump var="#message.getReferences()#" label="getReferences()">
 </cfloop>

If that works, try calling getFrom() which returns an EmailAddress object. Check the API, but it looks like you can access the address value using either:

    #message.getFrom().getAddress()#  ... or 
    #message.getFrom().get_Address()# 

(You get the idea ...)



来源:https://stackoverflow.com/questions/14652813/ews-api-and-coldfusion-how-to-reference-returned-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!