none
EWS Removing Email Address? RRS feed

  • Question

  • I am in Java, doing syncing over EWS of contacts. I can add new email addresses to a contact, and update existing email addresses. When we do a sync we make a changelist item  and send them over. However, I am not sure how to "blank out" an email address we already have.

    I try sending " " or null or "" as the email address 2 or 3 in the EmailAddressDictionaryType, but this causes nothing to change server side. Is there some special way to do this?

    So what would I need to send, XML wise, to make a exchange contact with 3 email addresses have 2 email address after the sync?


    • Edited by Brian Wawok Friday, August 14, 2009 9:31 PM
    Wednesday, August 5, 2009 4:32 PM

Answers

  • To remove an email address, you need to call UpdateItem and pass in a DeleteItemField change. Here's an example of that XML request:

    <UpdateItem ...>
    
      <ItemChanges>
    
        <t:ItemChange>
    
          <t:ItemId Id="id of the item you want to remove the email address from" ChangeKey="change key of the item" />
    
          <t:Updates>
    
            <t:DeleteItemField>
    
              <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress1" />
    
            </t:DeleteItemField>
    
          </t:Updates>
    
        </t:ItemChange>
    
      </ItemChanges>
    
    </UpdateItem>
    

    Regards,
    Kim Brandl

     


    Programming Writer, Microsoft Exchange Developer Documentation Team
    • Proposed as answer by Kim Brandl Wednesday, August 5, 2009 5:47 PM
    • Marked as answer by Brian Wawok Friday, August 14, 2009 9:30 PM
    Wednesday, August 5, 2009 5:46 PM

All replies

  • To remove an email address, you need to call UpdateItem and pass in a DeleteItemField change. Here's an example of that XML request:

    <UpdateItem ...>
    
      <ItemChanges>
    
        <t:ItemChange>
    
          <t:ItemId Id="id of the item you want to remove the email address from" ChangeKey="change key of the item" />
    
          <t:Updates>
    
            <t:DeleteItemField>
    
              <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress1" />
    
            </t:DeleteItemField>
    
          </t:Updates>
    
        </t:ItemChange>
    
      </ItemChanges>
    
    </UpdateItem>
    

    Regards,
    Kim Brandl

     


    Programming Writer, Microsoft Exchange Developer Documentation Team
    • Proposed as answer by Kim Brandl Wednesday, August 5, 2009 5:47 PM
    • Marked as answer by Brian Wawok Friday, August 14, 2009 9:30 PM
    Wednesday, August 5, 2009 5:46 PM
  • Does anyone know if there is an equivalent to this for the EWS API.

    I have tried many different ways to NULL out an email address on a contact:

     

    Dim email As New EmailAddress
    If Not String.IsNullOrEmpty(aContact.Item("Email1").ToString) Then
      email.Address = system.dbnull.value ' I also tied String.Empty and Nothing
    End If
    If Not String.IsNullOrEmpty(aContact.Item("Email1Description").ToString) Then
      email.Name = system.dbnull.value ' I also tied String.Empty and Nothing
    End If
    .EmailAddresses(EmailAddressKey.EmailAddress1) = email
    

    Each of the above ways of setting trying to remove an email address of a contact fails with different errors.


    Thanks Rob
    Friday, March 25, 2011 1:30 PM
  • Can you make sure that you are using EWS Managed API 1.1?

    Try setting the each email address index to a new, empty instance (don't set any poroperties) of the EmailAddress object and then update.

    If that doesn't work, try setting just one of the email addresses to a new empty instance and then call update. Repeat for the second email address. Can you report back to us the results?


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, March 28, 2011 3:55 PM
    Moderator
  • Micheal,

    Yes, I am targeting EWS Managed API 1.1.

    Dim email As New EmailAddress
    contact.EmailAddresses(EmailAddressKey.EmailAddress1) = email
    

    This error's:

       Object reference not set to an instance of an object.

    I have tried setting to nothing, null and empty string...

     

    Thanks


    Thanks Rob
    Monday, March 28, 2011 4:50 PM
  • Everyone here is the answer:

    Dim contact As New Contact(_EXService)
    Dim DispName__2 As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32896, MapiPropertyType.[String])
    Dim AddType As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32898, MapiPropertyType.[String])
    Dim EmailAdd As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32899, MapiPropertyType.[String])
    Dim OriginalDispName As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32900, MapiPropertyType.[String])
    Dim OriginalEntryId As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32901, MapiPropertyType.Binary)

    Dim userFields As ExtendedPropertyDefinition() = New ExtendedPropertyDefinition() {DispName__2, AddType, EmailAdd, OriginalDispName, OriginalEntryId}

    Dim extendedPropertySet As New PropertySet(BasePropertySet.FirstClassProperties, userFields)

    contact = contact.Bind(_EXService, New ItemId(_ITEMID), extendedPropertySet)

    With contact

       .RemoveExtendedProperty(DispName__2)
       .RemoveExtendedProperty(AddType)
       .RemoveExtendedProperty(EmailAdd)
       .RemoveExtendedProperty(OriginalDispName)
       .RemoveExtendedProperty(OriginalEntryId)

       .Save(WellKnownFolderName.Contacts)
    End With
    Thanks Rob
    Tuesday, April 19, 2011 1:06 PM