【问题标题】:How to set the contact title using the EWS Java API (Exchange Web Service)?如何使用 EWS Java API (Exchange Web Service) 设置联系人标题?
【发布时间】:2013-05-17 15:28:08
【问题描述】:

我想实现与这个问题中提出的完全相同的事情,但在 java 中:How to set the contact title using Exchange Web Services Managed API

我正在使用 EWS Java API 1.2 (http://archive.msdn.microsoft.com/ewsjavaapi)。 我可以使用 API 中公开的所有字段创建联系人,但不能创建标题(或 Email1DisplayName)。我尝试了这些组合(没有错误,但在 Outlook 中查看创建的联系人时,其标题仍为空):

contact.setExtendedProperty(new ExtendedPropertyDefinition(UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x3A45, MapiPropertyType.String), value);
contact.setExtendedProperty(new ExtendedPropertyDefinition((UUID) null, 0x3A45, MapiPropertyType.String), value);
contact.setExtendedProperty(new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String), value);

【问题讨论】:

    标签: exchangewebservices ewsjavaapi


    【解决方案1】:

    好的,我不知道我之前做错了什么,但我的问题中的一个选项确实适用于标题。这是完整的示例代码(我希望我以前有过):

    ExchangeService mailbox = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    mailbox.setUrl(new URL("https://remote.domain.com/EWS/exchange.asmx").toURI());
    ExchangeCredentials credentials = new WebCredentials("user.name", "password", "domain");
    mailbox.setCredentials(credentials);
    
    ExtendedPropertyDefinition titlePropDef = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);
    
    Contact c = new Contact(mailbox);
    c.setGivenName("GivenName");
    c.setSurname("Surname");
    c.getEmailAddresses().setEmailAddress(EmailAddressKey.EmailAddress1, new EmailAddress("asdf@asdf.com"));
    c.setExtendedProperty(titlePropDef, "TitleXYZ");
    c.save(WellKnownFolderName.Contacts);
    
    Contact result = (Contact) mailbox.findItems(WellKnownFolderName.Contacts, new ItemView(1)).iterator().next();
    
    PropertySet propertySet = new PropertySet(BasePropertySet.FirstClassProperties);
    propertySet.add(titlePropDef);
    result = Contact.bind(mailbox, result.getId(), propertySet);
    
    System.out.println("count: " + result.getExtendedProperties().getCount());
    
    for(ExtendedProperty p : result.getExtendedProperties())
    {
       System.out.println(p.toString());
    }
    

    【讨论】:

    • 您需要自定义身份验证器才能使其正常工作,而 EWS 代码库 1.2 版太旧了,如果不对代码库进行错误修复,很难使其正常工作。
    • 也许你有,但我没有。此代码适用于我,并且已发布在生产中。 EWS 代码库很旧,但它是我能找到的唯一免费库。如果你知道的话,请给我指一个更现代的图书馆。
    • 我在哪里可以找到每个属性的那些“ids”/“tags”(0x3A45)?
    • 请参阅我在第一段中链接到的问题。那里的答案有指向属性文档的链接。
    猜你喜欢
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多