2

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

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);
Community
  • 1
  • 1
Reto Höhener
  • 5,419
  • 4
  • 39
  • 79

1 Answers1

0

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("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());
}
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Reto Höhener
  • 5,419
  • 4
  • 39
  • 79
  • You need a Custom Authenticator to get this to work, and the EWS codebase version 1.2 is so old it is difficult to get it to work correctly without bug fixes to the codebase. – Eric Leschinski Aug 04 '13 at 14:18
  • Maybe you do, but I don't. This code works for me and is in production as posted. The EWS codebase is old, but it was the only free library I could find. Please do point me to a more modern library, if you know one. – Reto Höhener Aug 04 '13 at 16:37
  • Where can I find those "ids"/"tags" (0x3A45) for each property ? – Jan Aug 15 '18 at 14:55
  • See the question I linked to in the first paragraph. The answers there have links to the property docs. – Reto Höhener Aug 17 '18 at 08:45