public static ItemIdType CreateContactWithEmailAddresses(
ExchangeServiceBinding binding)
{
CreateItemType request = new CreateItemType();
request.Items = new NonEmptyArrayOfAllItemsType();
ContactItemType newContact = new ContactItemType();
// Set all the appropriate name fields
//
newContact.GivenName = "John";
newContact.Surname = "Doe";
newContact.FileAsMapping = FileAsMappingType.FirstSpaceLast;
newContact.FileAsMappingSpecified = true;
newContact.DisplayName = "John Doe";
newContact.Subject = "John Doe";
// Set up our single email address.
//
EmailAddressDictionaryEntryType address = new
EmailAddressDictionaryEntryType();
address.Key = EmailAddressKeyType.EmailAddress1;
address.Value = "johnnyd@contoso.com";
newContact.EmailAddresses = new EmailAddressDictionaryEntryType[] {
address };
// Now let's also set the email address display name and routing type
//
PathToExtendedFieldType emailDisplayPath =
PathToExtendedFieldType.BuildGuidId(
DistinguishedPropertySetType.Address,
32900,
MapiPropertyTypeType.String);
PathToExtendedFieldType emailRoutingPath =
PathToExtendedFieldType.BuildGuidId(
DistinguishedPropertySetType.Address,
32898,
MapiPropertyTypeType.String);
ExtendedPropertyType emailDisplayProp = new ExtendedPropertyType(
emailDisplayPath,
"Johnny Boy >> johnnyd@contoso.com");
ExtendedPropertyType emailRoutingProp = new ExtendedPropertyType(
emailRoutingPath,
"SMTP");
newContact.ExtendedProperty = new ExtendedPropertyType[] {
emailDisplayProp, emailRoutingProp };
request.Items.Items = new ItemType[] { newContact };
// Now make the call
//
ItemInfoResponseMessageType responseMessage =
binding.CreateItem(request).ResponseMessages.Items[0] as
ItemInfoResponseMessageType;
return responseMessage.Items.Items[0].ItemId;
}