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. 您應該在 Outlook 增益集類別中使用 ThisAddIn 以下程式碼範例, (使用適用於 Visual Studio) 的 Office 開發人員工具。 程式碼中的 Application 物件必須是由 提供信任ThisAddIn.Globals的 Outlook Application 物件。 如需使用 Outlook PIA 開發受管理 Outlook 解決方案的詳細資訊,請參閱 MSDN 上的 歡迎使用 Outlook 主要互通組件參考 。
程式碼範例顯示 DisplayAccountInformation 類別的方法 Sample ,實作為 Outlook 增益集專案的一部分。 每個專案都會新增一個以 Microsoft.Office.Interop.Outlook 命名空間為基礎的 Outlook PIA 參照。 此 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 |
屬性
另請參閱
帳戶物件成員傳送提供帳戶 SMTP 位址的電子郵件Outlook 物件模型參考
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。