本文介绍了如何使用EWS Java API(Exchange Web服务)设置联系人标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现与这个问题完全相同的东西,但是在java中:

I would like to achieve the exact same thing as asked in this question, but in 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中查看时,标题在创建的联系人中仍然为空):

I am using the EWS Java API 1.2 (http://archive.msdn.microsoft.com/ewsjavaapi).I can create a contact with all fields exposed in the API, but not the title (or Email1DisplayName). I tried these combinations (no errors, but title remains empty in the created contact when looking at it in 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);

推荐答案

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

Ok I don't know what I did wrong before, but one of the options in my question does work for the title. Here's the complete example code (I wish I had that before):

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("[email protected]"));
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 Java API(Exchange Web服务)设置联系人标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:37