我怎样才能得到Outlook ?smtp地址或samaccountname中的帐户

本文关键字:samaccountname 地址 smtp Outlook | 更新日期: 2023-09-27 18:19:14

环境: Outlook 2010(32位),Exchange 2010, Server 2008R2(64位)
开发环境: Visual Studio 2010 on Windows 7(64位)

我正在为Outlook 2010编写一个c#插件,我在指定发送电子邮件的帐户/电子邮件地址时遇到了问题。

我想从共享邮箱发送邮件;我有相应的邮箱权限。

通过编程,我有邮箱的SMTP地址(sharedacc@company.com)和邮箱的SAMAccountName (sharedacc)。

目前,我的代码看起来像这样:

Outlook.MailItem response = app.CreateItemFromTemplate(template.Path, folder) as Outlook.MailItem;
response.SendUsingAccount = ???<Outlook.Account>;

然而,我似乎找不到任何创建Outlook的方法。从SAMAccountName或SMTP地址获取Account对象。有办法吗?

我想我也许可以用:

response.Sender = ???<Outlook.AddressEntry>

但同样,我也找不到创建Outlook的方法。来自SAMAccountName或SMTP地址的AddressEntry。有人知道怎么做吗?

任何提示,链接,或大胆的猜测,非常感谢。

我怎样才能得到Outlook ?smtp地址或samaccountname中的帐户

如果您代表另一个Exchange邮箱发送,则只需设置MailItem。

您可以使用Application.Session.Accounts:

获取帐户
Outlook.Account account = Application.Session.Accounts["sharedacc"];
response.SendUsingAccount = account;

点击此链接。

如果你需要检查其他可用的帐户,你可以使用这个(从msdn复制粘贴):

StringBuilder builder = new StringBuilder();
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();
}