Account 对象 (Outlook)Account object (Outlook)

Account对象表示为当前配置文件定义的帐户。The Account object represents an account that is defined for the current profile.

备注Remarks

帐户集合对象和 帐户 对象的用途是提供枚举中给定配置文件,以标识类型的 帐户 ,并使用特定的 帐户 对象发送邮件的 帐户 对象的能力。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.

备注

[!注释] Helmut Obertanner 提供了以下代码示例。Helmut Obertanner provided the following code samples. Helmut 是 Microsoft 最有价值的专家 ,拥有 Microsoft Visual Studio Tools for Office 和 Microsoft Office Outlook 中的 Microsoft Office 开发工具方面的专业知识。Helmut is a Microsoft Most Valuable Professional with expertise in Microsoft Office development tools in Microsoft Visual Studio and Microsoft Office Outlook.

示例Example

下面的托管代码示例是使用 C# 和 Visual Basic 编写的。The following managed code samples are written in C# and Visual Basic. 若要运行需调入组件对象模型 (COM) 的 .NET Framework 托管代码示例,您必须使用可定义托管接口并将其映射到对象模型类型库中的 COM 对象的互操作程序集。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. 对于 Outlook,您可以使用 Visual Studio 和 Outlook 主互操作程序集 (PIA)。For Outlook, you can use Visual Studio and the Outlook Primary Interop Assembly (PIA). 在您运行适用于 Outlook 2013 的托管代码示例之前,请确保您已安装了 Outlook 2013 PIA 并且已添加了对 Visual Studio 中的 Microsoft Outlook 15.0 对象库组件的引用。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. 您应该使用 Outlook 加载项的 ThisAddIn 类中的以下代码示例(使用 Visual Studio Office 开发人员工具)。You should use the following code samples in the ThisAddIn class of an Outlook add-in (using Office Developer Tools for Visual Studio). 代码中的 应用程序对象必须是由 **** 提供的受信任 Outlook ThisAddIn.Globals对象。The Application object in the code must be a trusted Outlook Application object provided by ThisAddIn.Globals. 有关使用 Outlook PIA 开发托管的 Outlook 解决方案的详细信息,请参阅 MSDN 上的 Outlook 2013 Primary Interop Assembly ReferenceFor more information about using the Outlook PIA to develop managed Outlook solutions, see the Welcome to the Outlook Primary Interop Assembly Reference on MSDN.

下面的代码示例显示的 Outlook 外接程序项目的一部分实现的 DisplayAccountInformation类的 Sample方法。The following code samples show the DisplayAccountInformation method of the Sample class, implemented as part of an Outlook add-in project. 每个项目添加到 Outlook PIA,基于 Microsoft.Office.Interop.Outlook命名空间的引用。Each project adds a reference to the Outlook PIA, which is based on the Microsoft.Office.Interop.Outlook namespace. DisplayAccountInformation方法接受输入参数作为可信的 Outlook应用程序对象,并使用此 帐户 对象显示可用于当前 Outlook 配置文件的每个帐户的详细信息。The DisplayAccountInformation method takes as an input argument a trusted OutlookApplication 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: 
 builder.AppendLine("Exchange"); 
 break; 
 
 case Outlook.OlAccountType.olHttp: 
 builder.AppendLine("Http"); 
 break; 
 
 case Outlook.OlAccountType.olImap: 
 builder.AppendLine("Imap"); 
 break; 
 
 case Outlook.OlAccountType.olOtherAccount: 
 builder.AppendLine("Other"); 
 break; 
 
 case Outlook.OlAccountType.olPop3: 
 builder.AppendLine("Pop3"); 
 break; 
 } 
 
 builder.AppendLine(); 
 } 
 
 // Display the account information. 
 System.Windows.Forms.MessageBox.Show(builder.ToString()); 
 } 
 } 
}
Imports Outlook = Microsoft.Office.Interop.Outlook 
 
Namespace OutlookAddIn2 
 Class Sample 
 Shared Sub DisplayAccountInformation(ByVal application As Outlook.Application) 
 
 ' The Namespace Object (Session) has a collection of accounts. 
 Dim accounts As Outlook.Accounts = application.Session.Accounts 
 
 ' Concatenate a message with information about all accounts. 
 Dim builder As StringBuilder = New StringBuilder() 
 
 ' Loop over all accounts and print detail account information. 
 ' All properties of the Account object are read-only. 
 Dim account As Outlook.Account 
 For Each account In accounts 
 
 ' The DisplayName property represents the friendly name of the account. 
 builder.AppendFormat("DisplayName: {0}" & vbNewLine, account.DisplayName) 
 
 ' The UserName property provides an account-based context to determine identity. 
 builder.AppendFormat("UserName: {0}" & vbNewLine, account.UserName) 
 
 ' The SmtpAddress property provides the SMTP address for the account. 
 builder.AppendFormat("SmtpAddress: {0}" & vbNewLine, account.SmtpAddress) 
 
 ' The AccountType property indicates the type of the account. 
 builder.Append("AccountType: ") 
 Select Case (account.AccountType) 
 
 Case Outlook.OlAccountType.olExchange 
 builder.AppendLine("Exchange") 
 
 
 Case Outlook.OlAccountType.olHttp 
 builder.AppendLine("Http") 
 
 
 Case Outlook.OlAccountType.olImap 
 builder.AppendLine("Imap") 
 
 
 Case Outlook.OlAccountType.olOtherAccount 
 builder.AppendLine("Other") 
 
 
 Case Outlook.OlAccountType.olPop3 
 builder.AppendLine("Pop3") 
 
 
 End Select 
 
 builder.AppendLine() 
 Next 
 
 
 ' Display the account information. 
 Windows.Forms.MessageBox.Show(builder.ToString()) 
 End Sub 
 
 
 End Class 
End Namespace

方法Methods

名称Name
GetAddressEntryFromIDGetAddressEntryFromID
GetRecipientFromIDGetRecipientFromID

属性Properties

名称Name
AccountTypeAccountType
应用程序Application
AutoDiscoverConnectionModeAutoDiscoverConnectionMode
AutoDiscoverXmlAutoDiscoverXml
Class
CurrentUserCurrentUser
DeliveryStoreDeliveryStore
DisplayNameDisplayName
ExchangeConnectionModeExchangeConnectionMode
ExchangeMailboxServerNameExchangeMailboxServerName
ExchangeMailboxServerVersionExchangeMailboxServerVersion
ParentParent
SessionSession
SmtpAddressSmtpAddress
UserNameUserName

另请参阅See also

Account 对象成员

在给定帐户的 SMTP 地址的情况发送电子邮件Outlook 对象模型引用Account Object Members Send an email given the SMTP address of an account Outlook Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.