Beispiel #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // This function displays your first contact in your Contacts folder
        //
        // To do this:
        //		-first open up a MAPI session and login
        //		-then open the message store you want to send 
        //		-open your contacts folder 
        //
        // Use GetName to get the name (default DISPLAY NAME, but can be Initials, First Name etc) 
        // Use GetEmail to get the email address (named property) 
        // Use GetAddress to get the mailing address of CContactAddress::AddressType
        // Use GetPhoneNumber supplying a phone number property (ie BUSINESS_TELEPHONE_NUMBER)
        // Use GetNotes to get the notes in either plain text (default) or RTF
        //
        // Remember to Dispose of the contact when you're done with it!
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void ContactsTest(NetMAPI mapi)
        {
            if (mapi.OpenContacts() && mapi.GetContents())
            {
                // sort by name (stored in PR_SUBJECT)
                mapi.SortContents(true, SortFields.SORT_SUBJECT);

                MAPIContact contact;
                StringBuilder strText = new StringBuilder(NetMAPI.DefaultBufferSize);
                if (mapi.GetNextContact(out contact))
                {
                    if (contact.GetName(strText, MAPIContact.NameType.DISPLAY_NAME)) Console.WriteLine("Contact: " + strText);
                    if (contact.GetEmail(strText)) Console.WriteLine("Email: " + strText);
                    if (contact.GetCategories(strText)) Console.WriteLine("Categories: " + strText);

                    MAPIContact.ContactAddress address;
                    if (contact.GetAddress(out address, MAPIContact.AddressType.BUSINESS))
                    {
                        Console.WriteLine(address.Street);
                        Console.WriteLine(address.City);
                        Console.WriteLine(address.StateOrProvince);
                        Console.WriteLine(address.Country);
                        Console.WriteLine(address.PostalCode);
                    }

                    if (contact.GetPhoneNumber(strText, MAPIContact.PhoneType.BUSINESS_TELEPHONE_NUMBER)) Console.WriteLine("Phone: " + strText);

                    //usually you would call GetNotesSize first to ensure the buffer is large enough
                    if (contact.GetNotes(strText, false)) Console.WriteLine("Notes: " + strText);

                    contact.Dispose();
                }
            }
        }