How to: Get Account Information

This topic takes as an input argument a trusted Microsoft Outlook Application object, and uses the Account object to display the details of each account that is available for the current Outlook profile.

MVP Icon

Helmut Obertanner provided the following code examples. Helmut is a Microsoft Most Valuable Professional with expertise in Microsoft Office development tools in Microsoft Visual Studio and Microsoft Outlook. Helmut maintains a professional site at X4Uelectronix.

The following code examples contain the DisplayAccountInformation method of the Sample class, implemented as part of an Outlook add-in project. Each project adds a reference to the Outlook Primary Interop Assembly, which is based on the Microsoft.Office.Interop.Outlook namespace.

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

using Outlook = Microsoft.Office.Interop.Outlook;

The following is the Visual Basic code example, followed by the C# code example.

using System;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace OutlookAddIn1
    class Sample
        public static void DisplayAccountInformation(Outlook.Application application)

            // The Namespace Object (Session) has a collection of accounts.
            Outlook.Accounts accounts = application.Session.Accounts;

            // Concatenate a message with information about all accounts.
            StringBuilder builder = new StringBuilder();

            // Loop over all accounts and print detail account information.
            // All properties of the Account object are read-only.
            foreach (Outlook.Account account in accounts)

                // The DisplayName property represents the friendly name of the account.
                builder.AppendFormat("DisplayName: {0}\n", account.DisplayName);

                // The UserName property provides an account-based context to determine identity.
                builder.AppendFormat("UserName: {0}\n", account.UserName);

                // The SmtpAddress property provides the SMTP address for the account.
                builder.AppendFormat("SmtpAddress: {0}\n", account.SmtpAddress);

                // The AccountType property indicates the type of the account.
                builder.Append("AccountType: ");
                switch (account.AccountType)

                    case Outlook.OlAccountType.olExchange:

                    case Outlook.OlAccountType.olHttp:

                    case Outlook.OlAccountType.olImap:

                    case Outlook.OlAccountType.olOtherAccount:

                    case Outlook.OlAccountType.olPop3:


            // Display the account information.

Other Resources