EWS API 和 ColdFusion:如何引用返回值 [英] EWS API and ColdFusion: How to reference returned values
问题描述
我在处理复杂数组时遇到困难,需要一些帮助.我正在使用 EWS API 将邮件功能与 Exchange 2010 和 CF 集成.下面的代码连接到主帐户已委派权限的邮箱.我想返回收件箱中的邮件列表,并使用 EWS 返回的值(主题行、正文、发件人、收件人等).
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).
我以前没有使用过这样的复杂数组,所以我对如何引用返回的值感到困惑,特别是在 FindItemsResults 中返回的 getItems() 方法中.我查看了一个执行相同任务的 Java 示例,但是我无法理解这如何转换为 CF.CFDump 显示我正在获取信息,因此我确信连接按预期工作.我只需要获取数据,但不知道该怎么做.
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.
在此先感谢您的帮助.
<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()#">
推荐答案
(来自评论...)
所以看起来 ViewResults.getItems()
返回一个 EmailMessage
对象数组.EmailMessage 有很多方法.有些返回简单的值(布尔值、字符串、..),而其他的像 getFrom()
返回复杂的对象.
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.
尝试执行一个数组循环,并在其中输出一个简单的属性,例如:getIsRead()
或 getReferences()
.即
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>
如果可行,请尝试调用返回 EmailAddress
对象的 getFrom()
.检查 API,但您似乎可以使用以下任一方法访问地址值:
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()#
(你明白了……)
这篇关于EWS API 和 ColdFusion:如何引用返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!