【发布时间】:2010-12-11 13:50:40
【问题描述】:
我编写了一个 Outlook 插件,用于检索邮件项目的发件人的 SMTP 电子邮件地址。它在大多数机器上运行良好,但是,我有一台机器(我的新开发机器)每次尝试解析来自交换用户的电子邮件的 SMTP 地址时都会抛出 COMException。下面是我正在使用的代码...
private string SenderEmail(MailItem item)
{
if (item == null)
{
return "";
}
else
{
string senderEmail = string.Empty;
if (item.SenderEmailType.ToUpper() == "EX")
senderEmail = GetEmailAddressFromOU(item.SenderEmailAddress);
else
senderEmail = item.SenderEmailAddress;
return senderEmail;
}
}
private string GetEmailAddressFromOU(string ouName)
{
string emailAddress = string.Empty;
NameSpace oNS = ((Microsoft.Office.Interop.Outlook.Application)OutlookAppObj).GetNamespace("MAPI");
Recipient recip = oNS.CreateRecipient(ouName);
recip.Resolve();
ExchangeUser exUser = recip.AddressEntry.GetExchangeUser();
emailAddress = exUser.PrimarySmtpAddress;
Marshal.ReleaseComObject(exUser);
Marshal.ReleaseComObject(recip);
Marshal.ReleaseComObject(oNS);
return emailAddress;
}
访问收件人对象的 AddressEntry 属性时发生以下 COMException:
Message = "尝试操作失败。找不到对象。"
我使用的是 Windows 7(64 位),使用的是 Outlook 2010,但是相同的代码适用于具有相同操作系统和 Outlook 版本的其他机器。它在我以前的开发机器上也能正常工作,它也是 Windows 7(32 位)和 Outlook 2010。
我在 StackOverflow 和 Google 上搜索过任何解决方案,但没有找到任何解决方案。
谁能解释一下这个问题?
【问题讨论】:
-
更多信息:问题在于解析发件人的 LDAP 路径。在我尝试过的每台其他机器上,如果我将 LDAP 路径放在新电子邮件的“收件人”框中并单击“检查名称”,它将解析为正确的用户。在我的机器上,当我单击“检查名称”时,我收到“Microsoft Outlook 无法识别“...”消息。