【发布时间】:2020-03-31 03:50:31
【问题描述】:
我使用 .Net 核心创建了一个项目,如果我在我的一个页面中的“用户”文本框字段中输入任何名称或电子邮件,我必须匹配名称并获取可用的用户列表Outlook 的组织域。那么如何获取 Outlook 中可用的所有电子邮件地址或用户列表呢?
我尝试过以下方法,但我不熟悉此功能,我不知道如何连接我们的 Outlook 帐户并获取地址列表。谁能帮我解决这个问题?
public static void DisplayAccountInformation(Application application)
{
// The Namespace Object (Session) has a collection of accounts.
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 (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 OlAccountType.olExchange:
builder.AppendLine("Exchange");
break;
case OlAccountType.olHttp:
builder.AppendLine("Http");
break;
case OlAccountType.olImap:
builder.AppendLine("Imap");
break;
case OlAccountType.olOtherAccount:
builder.AppendLine("Other");
break;
case OlAccountType.olPop3:
builder.AppendLine("Pop3");
break;
}
builder.AppendLine();
}
// Display the account information.
}
我通过传递我的域名来调用函数,
var application = new Application();
application.CreateObject("outlook.office365.com");
DisplayAccountInformation(application);
【问题讨论】:
-
你有什么错误吗?你能解释一下为什么你的代码没有按预期工作吗?
-
错误:System.Runtime.InteropServices.COMException:'操作失败。' - 和代码行:“application.CreateObject("outlook.office365.com");"。这里的事情是我不知道如何指定我的域和服务器,我的代码是对还是错。
标签: c# outlook azure-active-directory office365 email-validation