views:

350

answers:

0

I'm creating an Outlook addin using VS 2008 and C#. In order to function this addin goes through all the e-mail using Redemption and parses it.

I've recently run into the issue of somebody opening outlook without a network connection (network offline, unplugged, or it's mobile like a laptop and happens to not have connectivity at the moment). It seems to be in getting a list of the recipients.

  
    System.Runtime.InteropServices.COMException (0x80040115): Error in IAddrBook::OpenEntry: MAPI_E_NETWORK_ERROR  
    Error: The connection to Microsoft Exchange is unavailable. Your network adapter does not have a default gateway.
    Component: Microsoft Exchange Address Book
        at Redemption.RDOAddressEntryClass.get_SMTPAddress()

This is happening within this code:

    /// <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;
    }

So the question is, how do I get the recipients of an e-mail without needing to authenticate to or resolve from Exchange and it dying because there's no network connection?

EDIT: Alternatively - is there a way to cache the smtp e-mail addresses within outlook so that if it later goes offline it doesn't have to resolve the e-mail addresses?