Search code examples
c#outlook-addin

How to set default addressbook via Addin


I need to change the addressbook a user sees when he writes an email. But I can't find any option to do this.

In general I see 2 ways to solve this problem: 1) Set the default addressbook 2) react when user opens 'Select Names' dialog and modify the initial addresslist

For option 1 I can't find any functions to do this and for option 2 i have only part of a solution.

foreach (Outlook.AddressList addrList in addrLists)
{
    Outlook.Folder testFolder = addrList.GetContactsFolder() as Outlook.Folder;

    if (Application.Session.CompareEntryIDs(testFolder.EntryID, addressbookID))
    {
        writeLog("passendes Adressbuch gefunden", 4);
        namesDialog.InitialAddressList = addrList;
        namesDialog.Display();
    }
}

With this code I can set initial addresslist and show the dialog but I don't know an event that happens when the 'to', 'cc' 'bcc' button is pressed.

Any ideas?


Solution

  • You cannot override the Outlook behavior when the user clicks the To/CC/BCC buttons. InitialAddressList property is only for when you explicitly show the address book dialog.

    On the MAPI level (C++ or Delphi), you would need to call IAddrBook.SetDefaultDir passing the entry id of the container (as well as set the PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY property to false in a profile section).

    Outlook Object Model does not expose that funcitonality. If using Redemption is an option (I am its author), it exposes RDOAddressBook.DefaultAddressList r/w property.