2

我正在使用 VS 2008 和 C# 创建一个 Outlook 插件。为了发挥作用,这个插件使用 Redemption 遍历所有电子邮件并对其进行解析。

我最近遇到了有人在没有网络连接的情况下打开 Outlook 的问题(网络脱机、拔掉插头,或者它像笔记本电脑一样是移动设备,并且目前恰好没有连接)。似乎是在获取收件人列表。

  
    System.Runtime.InteropServices.COMException (0x80040115):IAddrBook::OpenEntry 中的错误:MAPI_E_NETWORK_ERROR  
    错误:与 Microsoft Exchange 的连接不可用。您的网络适配器没有默认网关。
    组件:Microsoft Exchange 通讯簿
        在 Redemption.RDOAddressEntryClass.get_SMTPAddress()

这发生在这段代码中:

    /// <summary>
    /// Retrieves a list of recipient addresses from an RDOMail object
    /// </summary>
    /// <param name="rdoItem">The email to analyze</param>
    /// <returns>A list of e-mail addresses</returns>
    protected List<string> GetRecipients(RDOMail rdoItem)
    {
        RDORecipients recipients = rdoItem.Recipients;
        List<string> recipientList = new List<string>();
        if (recipients != null && recipients.Count > 0)
        {
            for (int i = 1; i <= recipients.Count; i++)
            {
                RDOAddressEntry addressEntry = recipients[i].AddressEntry;
                if (addressEntry != null)
                {
                    string recipient = addressEntry.SMTPAddress;
                    recipient = recipient.Trim();
                    if (recipient != null && recipient != String.Empty)
                    {
                        recipientList.Add(recipient);
                    }

                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(addressEntry);
                    addressEntry = null;
                }
            }
        }

        if (recipients != null)
        {
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(recipients);
            recipients = null;
        }

        return recipientList;
    }

所以问题是,我如何在不需要对 Exchange 进行身份验证或从 Exchange 解析的情况下获取电子邮件的收件人,并且它会因为没有网络连接而死掉?

编辑:或者 - 有没有办法在 Outlook 中缓存 smtp 电子邮件地址,以便以后脱机时不必解析电子邮件地址?

4

2 回答 2

1

在大多数情况下,PR_SMTP_ADDRESS 属性应该在收件人表中可用。您可以使用 RDORecipient.Fields[] 访问该属性 - 没有理由使用 RDORecipient.AddressEntry(这会导致 Redemption 调用 IAddrbook::OpenEntry,并且该调用可能在离线模式下失败)。

使用OutlookSpy查看收件人表(单击 IMessage,转到 GetRecipientTable 选项卡)以确保 PR_SMTP_ADDRESS 属性存在。

于 2014-10-08T20:11:49.397 回答
1

我相信一些商店提供商是底层 PST 商店的包装器。因此,当访问某些属性时,提供者将尝试与远程服务器同步。您应该能够通过从提供程序解开商店来阻止这种情况。

注意:例如,将项目添加到未包装的商店不应将该更改保留到服务器(在 IMAP4 的情况下)。

在Redemption 网站上阅读有关 UnwrapStore 属性的更多信息

于 2014-10-08T18:24:00.017 回答