Miha
Miha

Reputation: 313

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, e.g. 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?

Upvotes: 0

Views: 121

Answers (2)

Basic
Basic

Reputation: 26756

[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).

Upvotes: 0

DevinGanger
DevinGanger

Reputation: 11

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 = "[email protected]";
        oContact.Email1AddressType = "SMTP";
        oContact.Email1DisplayName =
            "Jacqueline Haddad ([email protected])";
        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);
    }
}

Upvotes: 0

Related Questions