简体   繁体   中英

How To Access Exchange 2003 Private (Contact) Items Programmatically

I'm looking for a way to programmatically (.Net) access PRIVATE contact folders on an Exchange 2003 server, to create a subfolder where to create contacts from a database.

The solutions I found so far rely on EWS, eg https://social.msdn.microsoft.com/Forums/en-US/aec6c998-f304-439c-9fa7-27bb9a4c4b45/problem-accessing-folders-in-another-mailbox?forum=exchangesvrdevelopment - such examples work for 2007+, the Exchange server I have to target is 2003.

Other examples are outlook Addins.

I need a standalone solution (an executable) that each time it runs, it's creating contacts from a DB into a particular subfolder under user's Contacts folder.

I also searched for some MAPI code samples (.Net) without much luck.

Could you please provide code (either VB.NET or C#) illustrating how to access a private mailbox Contacts folder (or a subfolder), to write a new contact item there?

If you're trying to do it from .Net, then you probably need to use the Outlook object as described in the conclusion to the Using MAPI to Create Outlook 2007 Items article on MSDN. CDO and RDO are meant to be used with VBscript and other unmanaged code.

Using this method, you're using C# to leverage Outlook 2007 (or better) automation in the given mailbox. Yes, it would require an account that would have appropriate access permissions to the target mailbox, and you'd have to iterate through the mailboxes and navigate the folder tree yourself.

The example they give is this:

private void AddContact()
{
    try
    {
        Outlook.ContactItem oContact =
            Application.CreateItem(
            Outlook.OlItemType.olContactItem)
            as Outlook.ContactItem;
        oContact.FirstName = "Jacqueline";
        oContact.LastName = "Haddad";
        oContact.Initials = "J.H.";
        oContact.CompanyName = "Microsoft";
        oContact.Email1Address = "someone@example.com";
        oContact.Email1AddressType = "SMTP";
        oContact.Email1DisplayName =
            "Jacqueline Haddad (someone@example.com)";
        oContact.BusinessAddressStreet = "1 Microsoft Way";
        oContact.BusinessAddressCity = "Redmond";
        oContact.BusinessAddressState = "WA";
        oContact.BusinessAddressPostalCode = "95802";
        oContact.BusinessAddressCountry = "USA";
        oContact.BusinessTelephoneNumber = "800-555-1212";
        oContact.WebPage = "http://www.codeplex.com/mfcmapi";
        oContact.Body = "This is a sample note.";
        oContact.Save();
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
}

[Promoted from a comment]

Entirely stand-alone is going to be problematic, but have a look at Redemption Data Objects which exposes the CDO/RDO mechanism used by outlook. It does require Outlook to be installed, but doesn't require it to be running (it uses the libraries, but doesn't work by automating Outlook).

We recently started using RDO and are getting much better performance than EWS.

Even if you don't use that, grab a (free) copy of OutlookSpy by the same company. It will expose a lot of info about how Exchange works internally, especially the data structures is uses (It adds a toolbar to Outlook, it's not stand alone).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM