Account Object (Outlook)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

The Account object represents an account that is defined for the current profile.

The purpose of the Accounts collection object and the Account object is to provide the capacity to enumerate Account objects in a given profile, to identify the type of Account, and to use a specific Account object to send mail.

Note Note

Helmut Obertanner provided the following code samples. Helmut is a Microsoft Most Valuable Professional with expertise in Microsoft Office development tools in Microsoft Visual Studio and Microsoft Office Outlook.

The following managed code samples are written in C# and Visual Basic. To run a .NET Framework managed code sample that needs to call into a Component Object Model (COM), you must use an interop assembly that defines and maps managed interfaces to the COM objects in the object model type library. For Outlook, you can use Visual Studio and the Outlook Primary Interop Assembly (PIA). Before you run managed code samples for Outlook 2013, ensure that you have installed the Outlook 2013 PIA and have added a reference to the Microsoft Outlook 15.0 Object Library component in Visual Studio. You should use the following code samples in the ThisAddIn class of an Outlook add-in (using Office Developer Tools for Visual Studio). The Application object in the code must be a trusted Outlook Application object provided by ThisAddIn.Globals. For more information about using the Outlook PIA to develop managed Outlook solutions, see the Welcome to the Outlook Primary Interop Assembly Reference on MSDN.

The following code samples show the DisplayAccountInformation method of the Sample class, implemented as part of an Outlook add-in project. Each project adds a reference to the Outlook PIA, which is based on the Microsoft.Office.Interop.Outlook namespace. The DisplayAccountInformation method takes as an input argument a trusted Outlook Application object, and uses the Account object to display the details of each account that is available for the current Outlook profile.

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.