如何使用Exchange Web服务(EWS)访问联系人的PostOfficeBox?

时间:2017-08-04 15:56:08

标签: outlook exchange-server exchangewebservices

我们使用outlook从客户的地址簿中导出信息。 现在他希望使用Exchange维护和更新信息。

我们决定使用Exchange Webservices API来实现此目的。

我可以检索联系人,在这些联系人中是包含工作,家庭和其他地址的PhysicalAddresses枚举。

这些地址是PhysicalAddressEntry类的实例。

此课程包含街道地址,邮政编码,城市,州和地区/国家/地区。 (见:https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.physicaladdressentry_members(v=exchg.80).aspx

但它不包含Outlook地址项具有的PostOfficeBox字段:

  • BusinessAddressPostOfficeBox
  • HomeAddressPostOfficeBox
  • MailingAddressPostOfficeBox
  • OtherAddressPostOfficeBox

(参见:https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/contactitem-object-outlook

Exchange Webservices API确实有一个PersonaPostalAddress类,它比PhysicalAddressEntry类更详细(参见:https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.personapostaladdress_properties(v=exchg.80).aspx)。那个确实有一个PostOfficeBox成员。

我没有成功从我的联系人中获取PersonaPostalAddress条目(参见:https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.contact_properties(v=exchg.80).aspx

有没有办法读取并可能编写属于某个地址的PostOfficeBox字段?

我们已经将“用户定义”属性作为扩展属性读取,这些属性位于PublicStrings命名空间中。 (见:https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.defaultextendedpropertyset(v=exchg.80).aspx

我尝试创建一个名为“OtherAddressPostOfficeBox”的扩展属性作为PublicStrings,Address和Common,但我还没有成功返回它。

原谅openge / progress代码,但这是我尝试过的:

DEFINE VARIABLE continent-regio           AS CLASS   Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition NO-UNDO.
DEFINE VARIABLE OtherAddressPostOfficeBox AS CLASS   Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition NO-UNDO.
DEFINE VARIABLE properties                AS CLASS   "Microsoft.Exchange.WebServices.Data.PropertyDefinitionBase[]" NO-UNDO.
ASSIGN continent-regio = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet:PublicStrings,"Continent/Regio",Microsoft.Exchange.WebServices.Data.MapiPropertyType:String).
ASSIGN OtherAddressPostOfficeBox = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet:Common,"OtherAddressPostOfficeBox",Microsoft.Exchange.WebServices.Data.MapiPropertyType:String).

ASSIGN properties = NEW "Microsoft.Exchange.WebServices.Data.PropertyDefinitionBase[]"(3).
properties:SetValue(continent-regio,0).
properties:SetValue(Microsoft.Exchange.WebServices.Data.ContactSchema:PostalAddressIndex,1).
properties:SetValue(OtherAddressPostOfficeBox,2).

contactlijst:PropertySet = NEW Microsoft.Exchange.WebServices.Data.PropertySet(
    Microsoft.Exchange.WebServices.Data.BasePropertySet:FirstClassProperties,
    properties).

DELETE OBJECT properties.

ASSIGN contacten = service:FindItems(Microsoft.Exchange.WebServices.Data.WellKnownFolderName:Contacts, contactlijst).

DO iX = 0 TO contacten:Items:COUNT - 1:
    IF STRING(contacten:Items:Item[iX]:GetType()) EQ "Microsoft.Exchange.WebServices.Data.Contact" THEN DO: /* Mailinglijsten overslaan */
        ASSIGN contactpersoon = CAST(contacten:Items:Item[iX], Microsoft.Exchange.WebServices.Data.Contact).

        DO iY = 0 TO contactpersoon:ExtendedProperties:COUNT - 1:
            CASE contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:NAME:
                WHEN continent-regio:NAME THEN ASSIGN tt-cp.continent-regio = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
                WHEN OtherAddressPostOfficeBox:NAME THEN MESSAGE contactpersoon:ExtendedProperties:ITEM[iY]:VALUE
                    VIEW-AS ALERT-BOX INFO BUTTONS OK.
            END CASE.
        END.

        DELETE OBJECT contactpersoon.
    END.
END.

我们可以通过这种方式读取自定义Continent/Regio字段,但不能读取PostOfficeBox字段。

我可能需要这些字段的数字ID才能使用ExtendedPropertyDefinition类的其他构造函数(请参阅:https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.extendedpropertydefinition_members(v=exchg.80).aspx),但我似乎无法找到它们。

我发现0x3A64(14948)可能是OtherAddressPostOfficeBox的ID,但是也没有用。

ASSIGN OtherAddressPostOfficeBox = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet:Address,14948,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String).

我使用了正确的属性标识符吗?它会以这种方式工作还是我需要做一些完全不同的事情?

编辑:我正在对Exchange联系人项目的这些地址字段进行暴力攻击,我在其中填写了每个可用字段的字段名称。对于大多数Exchange而言,Exchange响应内部服务器错误,但是,从32768开始,字段开始定期出现。

我现在可以确认ID 0x804A / 32842与BusinessAddressPostOfficeBox对应,所以希望在其他人弹出后立即添加答案。如果您碰巧知道如何直接从服务器提取PersonaPostalAddress,请随时发表评论。

我们有Microsoft Exchange Server 2010 SP3(14.3.123.4002)

1 个答案:

答案 0 :(得分:0)

这并不像我想象的那么简单,因为只有BusinessAddressPostOfficeBox是可以从Address DefaultExtendedPropertySet中检索的字段。

然而,有了这个字段,我设法在互联网上找到以下列表,解释如何获取其他字段:http://j-integra.intrinsyc.com/support/kb/article.aspx?id=53135

最终我们的代码现在看起来像这样:

ASSIGN BusinessAddressPostOfficeBox = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet:Address,32842,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       HomeAddressPostOfficeBox     = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14942,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       MailingAddressCity           = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14887,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       MailingAddressCountry        = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14886,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       MailingAddressPostalCode     = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14890,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       MailingAddressPostOfficeBox  = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14891,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       MailingAddressState          = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14888,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       MailingAddressStreet         = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14889,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)
       OtherAddressPostOfficeBox    = NEW Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14948,Microsoft.Exchange.WebServices.Data.MapiPropertyType:String)

ASSIGN properties = NEW "Microsoft.Exchange.WebServices.Data.PropertyDefinitionBase[]"(10).
properties:SetValue(continent-regio,0).
properties:SetValue(BusinessAddressPostOfficeBox,1).
properties:SetValue(HomeAddressPostOfficeBox,2).
properties:SetValue(MailingAddressCity,3).
properties:SetValue(MailingAddressCountry,4).
properties:SetValue(MailingAddressPostalCode,5).
properties:SetValue(MailingAddressPostOfficeBox,6).
properties:SetValue(MailingAddressState,7).
properties:SetValue(MailingAddressStreet,8).
properties:SetValue(OtherAddressPostOfficeBox,9).

contactlijst:PropertySet = NEW Microsoft.Exchange.WebServices.Data.PropertySet(
    Microsoft.Exchange.WebServices.Data.BasePropertySet:FirstClassProperties,
    properties).

ASSIGN contacten = service:FindItems(Microsoft.Exchange.WebServices.Data.WellKnownFolderName:Contacts, contactlijst).

DO iX = 0 TO contacten:Items:COUNT - 1:
    IF STRING(contacten:Items:Item[iX]:GetType()) EQ "Microsoft.Exchange.WebServices.Data.Contact" THEN DO: /* Mailinglijsten overslaan */
        ASSIGN contactpersoon = CAST(contacten:Items:Item[iX], Microsoft.Exchange.WebServices.Data.Contact).

        CREATE tt-cp.
        ASSIGN tt-cp.naam               = contactpersoon:CompleteName:FullName
               tt-cp.firma              = contactpersoon:CompanyName
               tt-cp.initialen          = contactpersoon:Initials
               tt-cp.functie            = contactpersoon:JobTitle
               tt-cp.afdeling           = contactpersoon:Department
/* ... */
        DO iY = 0 TO contactpersoon:ExtendedProperties:COUNT - 1:
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(continent-regio) THEN 
                ASSIGN tt-cp.continent-regio = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(BusinessAddressPostOfficeBox) THEN 
                ASSIGN tt-cp.werkadres-postbus = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(HomeAddressPostOfficeBox) THEN 
                ASSIGN tt-cp.thuisadres-postbus = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(MailingAddressCity) THEN 
                ASSIGN tt-cp.postadres-stad = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(MailingAddressCountry) THEN 
                ASSIGN tt-cp.postadres-land = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(MailingAddressPostalCode) THEN 
                ASSIGN tt-cp.postadres-postcode = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(MailingAddressPostOfficeBox) THEN 
                ASSIGN tt-cp.postadres-postbus = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(MailingAddressState) THEN 
                ASSIGN tt-cp.postadres-staat = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(MailingAddressStreet) THEN 
                ASSIGN tt-cp.postadres-straat = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(OtherAddressPostOfficeBox) THEN 
                ASSIGN tt-cp.anderadres-postbus = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
            IF contactpersoon:ExtendedProperties:ITEM[iY]:PropertyDefinition:Equals(Webpage) THEN 
                ASSIGN tt-cp.webstek = contactpersoon:ExtendedProperties:ITEM[iY]:VALUE.
        END.

所以基本上你只是查找你正在寻找的字段的标记id是什么,并为它创建一个扩展属性,然后它将被返回。

当检查返回的结果集时,您可以使用Equals测试propertydefinition以查看返回的结果。

相关问题