0

グローバル Outlook アドレス帳を使用して特定の電子メール アドレスから Exchange ユーザーを検索する小さな C# アプリケーションを作成する必要があります。名前で Exchange ユーザーを見つけるのは簡単ですが、プライマリ SMTP アドレスで見つけるにはどうすればよいですか? AddressList 全体を反復処理することはオプションではありません。膨大な (ほぼ 400k エントリ) ため、これには永遠に時間がかかります。より良い、より速い方法はありますか?

    public Outlook.ExchangeUser GetAddressBookEntry(string senderName, string senderAddress)
    {
        //Get Outlook address book
        Outlook.AddressList addressList = olNamespace.AddressLists["Globale Adressliste"];
        Outlook.AddressEntries addressEntries = addressList.AddressEntries;

        Outlook.ExchangeUser exUser = null;


        //Find corresponding entry in the address book
        //This always returns something even if the SenderName is not in the Address Book
        if (senderName != null)
        {
            Outlook.AddressEntry addressEntry = addressEntries[senderName];
            exUser = addressEntry.GetExchangeUser();
        }

        //Check if contact is correct (see above for reason)
        if (exUser != null && ((exUser.Name == senderName) || (exUser.PrimarySmtpAddress == senderAddress)))
        {
            return exUser;
        }

        //this loop takes a few minutes, it is not an option
        //not checking the address not implemented
        Debug.WriteLine("Count: " + addressEntries.Count);

        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 1; i <= addressEntries.Count; i++)
        {
            Outlook.AddressEntry addressEntry = addressEntries[i];

            if (i % 1000 == 0)
            {
                Debug.WriteLine(i);
            }
        }
        sw.Stop();
        Debug.WriteLine("Seconds: " + sw.Elapsed.TotalSeconds);

        return null;
    }
4

1 に答える 1

3

Namespace.CreateRecipient を呼び出し、Recipient.Resolve を呼び出してから、Recipient.AddressEntry プロパティを使用します。

于 2013-04-10T18:25:06.370 に答える