从 Outlook 加载项读取扩展属性
Read ExtendedProperties from Outlook Add-In
我目前正在使用 EWS Managed API (C#) 在 CalendarFolder
上设置自定义 ExtendedProperties
:
myCalendar.SetExtendedProperty(customExtendedProperty, true);
当我绑定 CalendarFolder
:
时,我还可以使用托管 API 加载这些设置
var myCalendar = CalendarFolder.Bind(service, folderId, requestedPropertySet);
接下来我想阅读这些相同的内容 ExtendedProperties
,但是来自使用 Office JavaScript 库的 Outlook 加载项。
从 Outlook 库的外观来看,没有公开 Office.context.item
的任何方法来访问 ExtendedProperties
。
库中是否有允许我访问它的方法?如果没有,我可以使用在 URL 路径 ("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/yourProp"
) 中具有 GUID 的模式方法吗?
要在插件中的文件夹上访问您自己的自定义属性,您需要使用 makeEwsRequestAsync https://dev.outlook.com/reference/add-ins/Office.context.mailbox.html#makeEwsRequestAsync to do a GetFolder in your Addin. To get the correct SOAP message just enabling tracing in you EWS Managed API code which will output the SOAP used https://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx which you can these transpose. The one thing to be aware of is the security requirements for making a makeEwsRequestAsync in your app eg ReadWriteMailbox http://dev.office.com/docs/add-ins/outlook/understanding-outlook-add-in-permissions
截至目前(2018 年 7 月),编写 Outlook 加载项时访问自定义扩展属性的首选方法是使用 ExtendedProperties REST API.
有一些示例代码展示了如何将 API 与 Office 加载项 JavaScript 库一起使用,可从 Office Dev Center.
获得
要使用API,您需要从当前的 Outlook 邮箱中获取授权令牌。这可以使用 Office.context.mailbox.getCallbackTokenAsync()
方法和关键字参数 {isRest: true}
来完成。您还应该使用 Office.context.mailbox.restUrl
属性 来为 API呼唤。
有几种方法可以从 JavaScript 实际进行 REST API 调用,但在客户端执行此操作的最简单方法是使用 AJAX 调用。在您的示例中,这看起来像:
const getMessageUrl = Office.context.mailbox.restUrl
+ "/v2.0/me/mailFolders/" + <folder id> + "?"
+ "$expand=singleValueExtendedProperties"
+ "($filter=PropertyId eq '<property id>')";
$.ajax({
url: getMessageUrl,
datatype: 'json',
headers: {'Authorization': 'Bearer ' + <auth token>}
}).then(item => {
// your code here
})
如果您有 属性 的 GUID,则 <属性 id> 将如下所示:
"String {00020329-0000-0000-C000-000000000046} Name yourProp"
如果您像我一样尝试访问早于 GUID 规则的 属性,那么您的 <属性 id> 可能如下所示:
"String 0x007D"
我目前正在使用 EWS Managed API (C#) 在 CalendarFolder
上设置自定义 ExtendedProperties
:
myCalendar.SetExtendedProperty(customExtendedProperty, true);
当我绑定 CalendarFolder
:
var myCalendar = CalendarFolder.Bind(service, folderId, requestedPropertySet);
接下来我想阅读这些相同的内容 ExtendedProperties
,但是来自使用 Office JavaScript 库的 Outlook 加载项。
从 Outlook 库的外观来看,没有公开 Office.context.item
的任何方法来访问 ExtendedProperties
。
库中是否有允许我访问它的方法?如果没有,我可以使用在 URL 路径 ("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/yourProp"
) 中具有 GUID 的模式方法吗?
要在插件中的文件夹上访问您自己的自定义属性,您需要使用 makeEwsRequestAsync https://dev.outlook.com/reference/add-ins/Office.context.mailbox.html#makeEwsRequestAsync to do a GetFolder in your Addin. To get the correct SOAP message just enabling tracing in you EWS Managed API code which will output the SOAP used https://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx which you can these transpose. The one thing to be aware of is the security requirements for making a makeEwsRequestAsync in your app eg ReadWriteMailbox http://dev.office.com/docs/add-ins/outlook/understanding-outlook-add-in-permissions
截至目前(2018 年 7 月),编写 Outlook 加载项时访问自定义扩展属性的首选方法是使用 ExtendedProperties REST API.
有一些示例代码展示了如何将 API 与 Office 加载项 JavaScript 库一起使用,可从 Office Dev Center.
获得要使用API,您需要从当前的 Outlook 邮箱中获取授权令牌。这可以使用 Office.context.mailbox.getCallbackTokenAsync()
方法和关键字参数 {isRest: true}
来完成。您还应该使用 Office.context.mailbox.restUrl
属性 来为 API呼唤。
有几种方法可以从 JavaScript 实际进行 REST API 调用,但在客户端执行此操作的最简单方法是使用 AJAX 调用。在您的示例中,这看起来像:
const getMessageUrl = Office.context.mailbox.restUrl
+ "/v2.0/me/mailFolders/" + <folder id> + "?"
+ "$expand=singleValueExtendedProperties"
+ "($filter=PropertyId eq '<property id>')";
$.ajax({
url: getMessageUrl,
datatype: 'json',
headers: {'Authorization': 'Bearer ' + <auth token>}
}).then(item => {
// your code here
})
如果您有 属性 的 GUID,则 <属性 id> 将如下所示:
"String {00020329-0000-0000-C000-000000000046} Name yourProp"
如果您像我一样尝试访问早于 GUID 规则的 属性,那么您的 <属性 id> 可能如下所示:
"String 0x007D"