Поделиться через


Объект account (Outlook)

Объект Account представляет учетную запись, определенную для текущего профиля.

Замечания

Цель объекта коллекции Accounts и объекта Account заключается в предоставлении возможности для перечисления объектов Account в заданном профиле, определения типа Account и использования определенного объекта Account для отправки почты.

Примечание.

Хельмут Обертаннер предоставил следующие примеры кода. Helmut является самым ценным специалистом Майкрософт с опытом работы с инструментами разработки Microsoft Office в Microsoft Visual Studio и Microsoft Office Outlook.

Пример

Следующие два примера управляемого кода написаны на C# и Visual Basic. Для запуска примера управляемого кода для .NET Framework, который вызывает модель COM, необходимо использовать сборку взаимодействия, которая определяет и сопоставляет управляемые интерфейсы с объектами COM в библиотеке типов объектной модели. Для Outlook можно использовать Visual Studio и первичную сборку взаимодействия Outlook (PIA). Перед запуском примеров управляемого кода для Outlook 2013 убедитесь, что вы установили Outlook 2013 PIA и добавили ссылку на компонент Microsoft Outlook 15.0 Object Library в Visual Studio. В классе надстройки Outlook следует использовать следующие примеры ThisAddIn кода (с помощью средств разработчика Office для Visual Studio). Объект Application в коде должен быть доверенным объектом Application Outlook, предоставленным объектом ThisAddIn.Globals. Дополнительные сведения об использовании Outlook PIA для разработки управляемых решений Outlook см. в статье Справочник по основной сборке взаимодействия Outlook на веб-сайте MSDN.

В примерах DisplayAccountInformationSample кода показан метод класса , реализованный как часть проекта надстройки 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

См. также

Члены объекта учетной записиОтправка сообщения электронной почты с указанием SMTP-адреса учетной записи Справочник пообъектной модели Outlook

Поддержка и обратная связь

Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь.