C# 如何从smtp地址或samaccountname获取Outlook.Account?
环境:Outlook 2010(32位)、Exchange 2010、服务器2008R2(64位)C# 如何从smtp地址或samaccountname获取Outlook.Account?,c#,outlook,outlook-addin,C#,Outlook,Outlook Addin,环境:Outlook 2010(32位)、Exchange 2010、服务器2008R2(64位) 开发环境:Windows 7(64位)上的Visual Studio 2010 我正在为Outlook 2010编写一个C#加载项,但在指定发送电子邮件的帐户/电子邮件地址时遇到问题 我想从共享邮箱发送电子邮件;我对邮箱有适当的权限 从程序上讲,我有邮箱的SMTP地址(sharedacc@company.com)以及邮箱的SAMAccountName(sharedacc) 目前,我的代码如下所示:
开发环境:Windows 7(64位)上的Visual Studio 2010 我正在为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.MailItem response=app.CreateItemFromTemplate(template.Path,文件夹)作为Outlook.MailItem;
response.SendUsingAccount=???;
但是,我似乎找不到任何方法从SAMAccountName或SMTP地址创建Outlook.Account对象有办法吗?
我想我可以改为使用:
response.Sender = ???<Outlook.AddressEntry>
response.Sender=???
但类似地,我找不到从SamaAccountName或SMTP地址创建Outlook.AddressEntry的方法有人知道怎么做吗?
非常感谢您的任何提示、链接或猜测。如果您是代表另一个Exchange邮箱发送,则只需在调用Send之前设置MailItem.SentonBehalfName属性。您可以使用
Application.Session.Accounts
获取帐户:
Outlook.Account account = Application.Session.Accounts["sharedacc"];
response.SendUsingAccount = account;
看看这个
如果您需要检查其他可用帐户,您可以使用(从msdn复制粘贴):
非常感谢你,但这对我不起作用。我只有一个“账户”,那是我自己的外汇账户。“sharedacc”纯粹是一个共享邮箱,我对其拥有完全访问/发送权限。如果我遍历Application.Session.Accounts.Wow,它不会出现!我怎么会不知道呢?!=)这适用于SMTP地址或SAMAccountName。非常感谢。
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();
}