繁体   English   中英

访问多个Outlook帐户的全局地址列表

[英]Accessing Global Address Lists for multiple Outlook accounts

经过数小时的搜索,在这里尝试我的运气。

假设您有一个带有两个活动帐户的Outlook 2010:john.doe @ company.com,admin.test @ company.com。

您需要为admin.test@company.com拉全局地址列表:

            using Microsoft.Office.Interop.Outlook;

            Application app = new Application();
            NameSpace ns = app.GetNamespace("MAPI");
            ns.Logon("", "", false, true);

            AddressList GAL = ns.AddressLists["Global Address List"];

            foreach (AddressEntry oEntry in GAL.AddressEntries)
            {
                // do something
            }

这里的问题是GAL可以属于任何一个帐户,而且至少通过阅读MSDN来了解您如何指定您真正想要使用的帐户,这并不明显。

如果我们将浏览所有这样的列表:

foreach (AddressList lst in ns.AddressLists)
{
    Console.WriteLine("{0}, {1}", lst.Name, lst.Index);
}

我们可以看到有两个名为“ Global Address List”的条目,两个名为“ Contacts”的条目,等等,它们具有不同的索引,但是仍然不清楚哪个属于哪个帐户。

对于文件夹,它可以很好地完成,因为您可以使用如下构造:

ns.Folders["admin.test@company.com"].Folders["Inbox"];

但是我不知道地址列表的类似机制。

任何帮助表示赞赏。

谢谢。

需要使用配置文件(IProfAdmin)和帐户管理API(IOlkAccountManager)将来自不同服务器的GAL与相应的商店和帐户相关联。 这些接口只能在C ++或Delphi中访问。 您将需要同时从商店(IMsgSTore)和地址簿对象(IABContainer)中读取PR_EMSMDB_SECTION_UID。 如果需要将其与某个帐户进行匹配,则IOlkAccount对象中的PROP_MAPI_EMSMDB_SECTION_UID(0x20070102)属性中将提供相同的值-如果您单击IOlkAccountManager按钮并双击一个Exchange帐户,则可以在OutlookSpy中看到它。

如果使用“ 兑换”是一个选项,则可以使用RDOExchangeAccount对象,该对象公开GAL,AllAddressLists,PrimaryStore,PublicFolders等属性。

我使用Account.CurrentUser UID和匹配的AddressList UID选择正确的列表。 我不知道使用Store是否是更好的方法,但是这种方法效果很好。

理查德(Richard)和德米特里(Dmitry)谢谢您的帮助。

另外,德米特里(Dmitry)非常感谢您维护Internet上所有可用MAPI标签的唯一来源。

码:

using Microsoft.Office.Interop.Outlook;

const string PR_EMSMDB_SECTION_UID = "http://schemas.microsoft.com/mapi/proptag/0x3D150102";

Application app = new Application();
NameSpace ns = app.GetNamespace("MAPI");
ns.Logon("", "", false, true);

string accountName = "admin.test@company.com";
string accountUID = null;

// Get UID for specified account name
foreach (Account acc in ns.Accounts)
{
    if (String.Compare(acc.DisplayName, accountName, true) == 0)
    {
        PropertyAccessor oPAUser = acc.CurrentUser.PropertyAccessor;
        accountUID = oPAUser.BinaryToString(oPAUser.GetProperty(PR_EMSMDB_SECTION_UID));
        break;
    }
}

// Select GAL with matched UID
foreach (AddressList GAL in ns.AddressLists)
{
    if (GAL.Name == "Global Address List")
    {
        PropertyAccessor oPAAddrList = GAL.PropertyAccessor;
        if (accountUID == oPAAddrList.BinaryToString(oPAAddrList.GetProperty(PR_EMSMDB_SECTION_UID)))
        {
            foreach (AddressEntry oEntry in GAL.AddressEntries)
            {
                // do something
            }
            break;
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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