【问题标题】:Outlook Interop AddressEntry ExceptionOutlook 互操作地址条目异常
【发布时间】: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 无法识别“...”消息。

标签: interop outlook


【解决方案1】:

仍然不确定是什么导致了问题,但删除了我在 Outlook 中的所有电子邮件帐户并重新添加它们,解决了问题。

【讨论】:

    【解决方案2】:

    要解决帐户问题,请尝试删除 OST 文件。 此链接说明了如何操作:
    http://social.technet.microsoft.com/Forums/en/w7itprogeneral/thread/d8fe1d52-4f95-4158-ab2f-13cab5cbabf9

    【讨论】:

      猜你喜欢
      • 2013-08-24
      • 1970-01-01
      • 2023-04-10
      • 2016-02-02
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      相关资源
      最近更新 更多