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?
I believe some store providers are wrappers around underlying PST stores. Therefore when accessing certain properties the provider will attempt to sync with the remote server. You should be able to stop this by unwrapping the store from the provider.
Note: that adding an item to an unwrapped store shouldn't persist that change to the server (in the case of IMAP4) for example.
Read more about the UnwrapStore property here at the Redemption website
In most cases PR_SMTP_ADDRESS property should be available in the recipient table. You can access that property using RDORecipient.Fields[] - there is no reason to use RDORecipient.AddressEntry (which causes Redemption to call IAddrbook::OpenEntry, and the call can fail in the offline mode).
Look at the recipient table with OutlookSpy (click IMessage, go to the GetRecipientTable tab) to make sure the PR_SMTP_ADDRESS property is present.
User contributions licensed under CC BY-SA 3.0