共用方式為


列舉全域通訊清單中的專案

本範例會列舉全域通訊清單中前 100 個主要的簡易郵件傳輸通訊協定 (SMTP) 位址, (GAL) 。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

在下列程式代碼範例中,AddressEntry 物件的 SMTP 位址是在呼叫 GetExchangeUser () 或 GetExchangeDistributionList () 方法時,將它轉換成 ExchangeUserExchangeDistributionList 物件來取得。 如果 AddressEntry 物件代表 Exchange 使用者,EnumerateGAL 會傳回公開 AddressEntry 物件屬性的 ExchangeUser 物件。 使用 ExchangeUser 屬性,例如 JobTitleDepartmentAliasBusinessTelephoneNumberPrimarySmtpAddress 來公開它們。

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void EnumerateGAL()
{
    Outlook.AddressList gal =
        Application.Session.GetGlobalAddressList();
    if (gal != null)
    {
        for (int i = 1; 
            i <= Math.Min(100, gal.AddressEntries.Count - 1); i++)
        {
            Outlook.AddressEntry addrEntry =
                gal.AddressEntries[i];
            if (addrEntry.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeUserAddressEntry
                || addrEntry.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeRemoteUserAddressEntry)
            {
                Outlook.ExchangeUser exchUser =
                    addrEntry.GetExchangeUser();
                Debug.WriteLine(exchUser.Name + " "
                    + exchUser.PrimarySmtpAddress);
            }
            if (addrEntry.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeDistributionListAddressEntry)
            {
                Outlook.ExchangeDistributionList exchDL =
                    addrEntry.GetExchangeDistributionList();
                Debug.WriteLine(exchDL.Name + " "
                    + exchDL.PrimarySmtpAddress);
            }
        }
    }
}

另請參閱

通訊錄