Create Contact

The Create Contact demo application demonstrates how to create a Contact using EWS.

Example code:


  // Logon and create the message
  EWSSession.Active := True;
  try
    NewContact := EWSSession.CreateMessage(dfinContacts) as IRwEWSContact;

    NewContact.BodyText                 := memoBody.Text;

    NewContact.CompleteName.Title       := EdtTitle.Text;
    NewContact.CompleteName.FirstName   := edtFirstName.Text;
    NewContact.CompleteName.LastName    := edtLastName.Text;
    NewContact.FileAs                   := EdtFileUnder.Text;
    NewContact.CompanyName              := EdtCompany.Text;
    NewContact.IsPrivate                := chBxPrivate.Checked;

    if EdtIMAddress.Text  '' then
      NewContact.ImAddresses.Entry[iakImAddress1].Value := EdtIMAddress.Text;

    if EdPhoneHome.Text  '' then
      NewContact.PhoneNumbers.Entry[pnkHomePhone].Value := EdPhoneHome.Text;

    if EdPhoneWork.Text  '' then
      NewContact.PhoneNumbers.Entry[pnkBusinessPhone].Value := EdPhoneWork.Text;

    if EdtFax.Text  '' then
      NewContact.PhoneNumbers.Entry[pnkBusinessFax].Value := EdtFax.Text;

    if EdtMobile.Text  '' then
      NewContact.PhoneNumbers.Entry[pnkMobilePhone].Value := EdtMobile.Text;

    if EWSSession.ServerVersion >= Exchange2013 then
      NewContact.Urls.Url[cukPersonal].Address := EdtWebSite.Text;

    if MemoAddress.Text  '' then
    begin
      case tBtnAddress.Tag of
        0: AddressKey := pakHome;
        1: AddressKey := pakBusiness;
      else
        AddressKey := pakOther;
      end;

      NewContact.PhysicalAddresses.Entry[AddressKey].Street          := FStreet;
      NewContact.PhysicalAddresses.Entry[AddressKey].PostalCode      := FZip;
      NewContact.PhysicalAddresses.Entry[AddressKey].City            := FCity;
      NewContact.PhysicalAddresses.Entry[AddressKey].State           := FState;
      NewContact.PhysicalAddresses.Entry[AddressKey].Street          := FStreet;
      NewContact.PhysicalAddresses.Entry[AddressKey].CountryOrRegion := FCountry;
    end;

    if EdtEMailDisplay.Text  '' then
    begin
      NewContact.EmailAddresses.Entry[eakEmailAddress1].Name         := EdtEMailDisplay.Text;
      NewContact.EmailAddresses.Entry[eakEmailAddress1].RoutingType  := 'SMTP';
      NewContact.EmailAddresses.Entry[eakEmailAddress1].MailboxType  := mtOneOff;
      NewContact.EmailAddresses.Entry[eakEmailAddress1].Value        := EdtEMail.Text;
    end;

    if EdtEMail2.Text  '' then
    begin
      NewContact.EmailAddresses.Entry[eakEmailAddress2].Name         := EdtEMail2Display.Text;
      NewContact.EmailAddresses.Entry[eakEmailAddress2].RoutingType  := 'SMTP';
      NewContact.EmailAddresses.Entry[eakEmailAddress2].MailboxType  := mtOneOff;
      NewContact.EmailAddresses.Entry[eakEmailAddress2].Value        := EdtEMail2.Text;
    end;

    if EdtEMail3.Text  '' then
    begin
      NewContact.EmailAddresses.Entry[eakEmailAddress3].Name         := EdtEMail3Display.Text;
      NewContact.EmailAddresses.Entry[eakEmailAddress3].RoutingType  := 'SMTP';
      NewContact.EmailAddresses.Entry[eakEmailAddress3].MailboxType  := mtOneOff;
      NewContact.EmailAddresses.Entry[eakEmailAddress3].Value        := EdtEMail3.Text;
    end;

    NewContact.SaveChanges;
  finally
    EWSSession.Active := False;
  end;

Screenshot:


Back to Examples