问题描述
我无法使用复杂数组,可以使用一些帮助。我正在使用EWS API将邮件功能与Exchange 2010和CF集成。以下代码连接到主要帐户已授权的邮箱。我想返回收件箱中的邮件列表,并使用EWS返回的值(主题行,正文,从,到等)。
我没有使用这样的复杂数组,所以我很困惑如何引用返回的值,特别是在FindItemsResults中返回的getItems()方法。我已经看了一个Java示例,做这个相同的任务,但我有麻烦让我的心包装如何转换为CF。 CFDump显示我收到的信息,所以我有信心,连接是按预期工作。我只需要获取数据,不知道该怎么做。
感谢您的帮助。
< cfobject type =Javaclass =microsoft.exchange.webservices.data.ExchangeServicename =service>
< cfset service.init()>
< cfobject type =Javaclass =microsoft.exchange.webservices.data.WebCredentialsname =credentials>
< cfset service.setCredentials(credentials)/>
< cfset service.AutodiscoverUrl([email protected])>
< cfobject type =javaclass =microsoft.exchange.webservices.data.WellKnownFolderNamename =WellKnownFolderName>
< cfset ViewResults = service.findItems(CreateObject(java,microsoft.exchange.webservices.data.FolderId)。init(WellKnownFolderName.Inbox,
CreateObject ,microsoft.exchange.webservices.data.Mailbox)。init([email protected],SMTP)),
CreateObject(java,microsoft.exchange.webservices.data。 ItemView)。init(3))/>
< cfdump var =#ViewResults#>
< cfdump var =#ViewResults.getItems()#>
b
$ b
所以看起来像 ViewResults.getItems()
返回一个 EmailMessage
对象。 EmailMessage有很多方法。一些返回简单的值(布尔,字符串,..)和其他像 getFrom()
返回复杂的对象。
尝试执行数组循环,并在其中输出一个简单的属性,如: getIsRead()
或 getReferences()
。即
< cfloop array =#itemsArray#index =message>
< cfdump var =#message.getIsRead()#label =getIsRead()>
< cfdump var =#message.getReferences()#label =getReferences()>
< / cfloop>
如果有效,请尝试调用 getFrom()
它返回一个 EmailAddress
对象。检查API,但看起来您可以使用以下任一方式访问地址值:
#message.getFrom()getAddress )#...或
#message.getFrom()。get_Address()#
(你得到的想法...)
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 protected]")>
<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("[email protected]","SMTP")),
CreateObject("java","microsoft.exchange.webservices.data.ItemView").init(3)) />
<cfdump var="#ViewResults#">
<cfdump var="#ViewResults.getItems()#">
(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 ...)
这篇关于EWS API和ColdFusion:如何引用返回的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!