我正在使用 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 电子邮件地址,以便以后脱机时不必解析电子邮件地址?