Beispiel #1
0
        public static void Run()
        {
            // ExStart:AddContactsToExchangeServerUsingEWS
            // Set mailboxURI, Username, password, domain information
            string            mailboxUri  = "https://ex2010/ews/exchange.asmx";
            string            username    = "******";
            string            password    = "******";
            string            domain      = "ex2010.local";
            NetworkCredential credentials = new NetworkCredential(username, password, domain);
            IEWSClient        client      = EWSClient.GetEWSClient(mailboxUri, credentials);

            //Create New Contact
            Contact contact = new Contact();

            //Set general info
            contact.Gender      = Gender.Male;
            contact.DisplayName = "Frank Lin";
            contact.CompanyName = "ABC Co.";
            contact.JobTitle    = "Executive Manager";

            //Add Phone numbers
            contact.PhoneNumbers.Add(new PhoneNumber {
                Number = "123456789", Category = PhoneNumberCategory.Home
            });

            //contact's associated persons
            contact.AssociatedPersons.Add(new AssociatedPerson {
                Name = "Catherine", Category = AssociatedPersonCategory.Spouse
            });
            contact.AssociatedPersons.Add(new AssociatedPerson {
                Name = "Bob", Category = AssociatedPersonCategory.Child
            });
            contact.AssociatedPersons.Add(new AssociatedPerson {
                Name = "Merry", Category = AssociatedPersonCategory.Sister
            });

            //URLs
            contact.Urls.Add(new Url {
                Href = "www.blog.com", Category = UrlCategory.Blog
            });
            contact.Urls.Add(new Url {
                Href = "www.homepage.com", Category = UrlCategory.HomePage
            });

            //Set contact's Email address
            contact.EmailAddresses.Add(new EmailAddress {
                Address = "*****@*****.**", DisplayName = "Frank Lin", Category = EmailAddressCategory.Email1
            });

            try
            {
                client.CreateContact(contact);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:AddContactsToExchangeServerUsingEWS
        }