共用方式為


Outlook) (帳戶物件

Account 物件代表為目前設定檔所定義的帳戶。

註解

Accounts 集合物件和 Account 物件的目的在於支援列舉所指定設定檔中的 Account 物件、識別 Account 的類型,以及使用特定的 Account 物件來傳送郵件。

注意事項

Helmut Obertanner 提供了下列程式碼範例。 Helmut 是 Microsoft 最有價值專家 ,具備 Microsoft Visual Studio 和 Microsoft Office Outlook 中 Microsoft Office 開發工具的專業知識。

範例

下列兩個 Managed 程式碼範例是以 C# 和 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. 您應該使用 Office Developer Tools for Visual Studio) ,在 Outlook 增益集 (類別中使用下列程式碼 ThisAddIn 範例。 程式碼中的Application物件必須是 所 ThisAddIn.Globals 提供的受信任 Outlook應用程式物件。 如需使用 Outlook PIA 開發受控 Outlook 解決方案的詳細資訊,請參 閱 MSDN 上的歡迎使用 Outlook 主要 Interop 元件參考

程式碼範例會顯示 DisplayAccountInformation 類別的 Sample 方法,實作為 Outlook 增益集專案的一部分。 每個專案都會新增 Outlook PIA 的參考,以 Microsoft.Office.Interop.Outlook 命名空間為基礎。 方法 DisplayAccountInformation 會將 受信任 的 Outlook 應用程式 物件當做輸入引數,並使用 Account 物件來顯示目前 Outlook 設定檔可用之每個帳戶的詳細資料。

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

方法

名稱
GetAddressEntryFromID
GetRecipientFromID

屬性

名稱
AccountType
Application
AutoDiscoverConnectionMode
AutoDiscoverXml
Class
CurrentUser
DeliveryStore
DisplayName
ExchangeConnectionMode
ExchangeMailboxServerName
ExchangeMailboxServerVersion
Parent
Session
SmtpAddress
UserName

另請參閱

帳戶物件成員根據帳戶Outlook 物件模型參考的 SMTP 位址傳送電子郵件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應