Outlook Web加载项如何将信息保存到EWS中的客户属性 [英] Outlook web add-in How to save info to customer properties in EWS

查看:54
本文介绍了Outlook Web加载项如何将信息保存到EWS中的客户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Office.js API,我们可以轻松地通过 customProps.set 将额外的信息保存到 CustomProperties 对象中.该信息特定于邮件项目.

这是文档保存使用office.js自定义属性

我可以使用 EWS API实现相同的功能吗?

我尝试了

JS代码:

  Office.context.mailbox.item.loadCustomPropertiesAsync(function(asyncResult){var customProps = asyncResult.value;console.log(customProps);console.log(customProps.get('到期日期'));//不明确的}) 

可以,但是这些类型的属性遵循特定的格式,因为它们是特定于应用程序的. https://msdn.microsoft.com/en-us/library/hh968549(v = exchg.80).aspx .它们是String类型的PS_PUBLIC_STRING属性集中的一个命名属性.该属性的属性名称以cecp-为前缀,其余的属性是您的Mail Apps的GUID(如应用程序清单Id中所定义).最好的查看方法是查看在MAPI编辑器(如MFCMapi的OutlookSpy)中设置属性的项目,在该项目中您可以看到属性(易于使用Cecp前缀识别)和值的格式(JSON)

编辑代码示例

  ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,"cecp-a8e14732-37cf-4a46-b69f-1111111111",MapiPropertyType.String);Email.SetExtendedProperty(extendedPropertyDefinition,"{\"到期日期\:\"等等\}"); 

Using Office.js API we can easily save extra info to the CustomProperties object via customProps.set. The information is specific to the mail item.

The is the doc Save to custom properties using office.js

Can I achieve the same thing using EWS API?

I tried Creating custom extended properties by using the EWS Managed API 2.0 But whatever info saved via this method I cannot retrieve it using Office.js 's customProps.get.

The User case is that my add-in will save the email body and its attachments binary to the external application. Upon finish the client side will use Office.js 's customProps.set to save the success info to the server, and if you click the same email next time the app will use customProps.get to show you the email has been saved. But if during the lengthy save process(maybe save a big attachment, the user close the task pane, before the customProps.set is executed, the customProps.set will simply not fire because the browser environment (task pane) is closed. So I need to implement this using EWS's API.

My C# code:

Guid PS_PUBLIC_STRINGS = new Guid("a8e14732-37cf-4a46-b69f-1111111111");//add-in manifest id

        ExtendedPropertyDefinition extendedPropertyDefinition =
        new ExtendedPropertyDefinition(PS_PUBLIC_STRINGS, "Expiration Date", MapiPropertyType.String);
        Email.SetExtendedProperty(extendedPropertyDefinition, DateTime.Now.AddDays(2).ToString());
        Email.Update(ConflictResolutionMode.AlwaysOverwrite);//'The requested web method is unavailable to this caller or application.'

JS Code:

Office.context.mailbox.item.loadCustomPropertiesAsync(function (asyncResult) {
                var customProps = asyncResult.value;
                console.log(customProps);
                console.log(customProps.get('Expiration Date')); //undefined
})

解决方案

Yes you can do that but these type of properties follow a specific format because they are application specific. This is documented in https://msdn.microsoft.com/en-us/library/hh968549(v=exchg.80).aspx. They are a named property within the PS_PUBLIC_STRING propset of type String. The property name of the property is prefixed with cecp- and rest of the property name is the GUID of your Mail Apps as defined in the application's manifest Id . The best way to see this is look at item where you have set the property in a MAPI editor like OutlookSpy of MFCMapi where you can see the property (easy to identify with the Cecp prefix) and the format for the value (JSON)

Edit Code example

        ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "cecp-a8e14732-37cf-4a46-b69f-1111111111", MapiPropertyType.String);
        Email.SetExtendedProperty(extendedPropertyDefinition, "{\"Expiration Date\":\"blah\"}");

这篇关于Outlook Web加载项如何将信息保存到EWS中的客户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆