Someone called Chris_is_tired alerted me to a problem with my NoReplyAll Outlook add-in recently: if you happen to have the Outbox in view and send an email, it seems to never leave the Outbox when the add-in is loaded. Without the add-in, it's fine. A bit of web searching found lots of references to emails getting stuck in the Outbox - a knowledge base article and a VSTO forum post put me on the right track, which is whatever you do, don't touch the Outbox!
In an earlier blog post, I talked about accessing the currently selected MailItem in an Explorer pane and it transpires that that programmatic access is sufficient to make Outlook act as if the user has opened the email which, if the current folder is the Outbox, means the email won't be sent. After scratching my head a little bit, I came up with this rather crude check to avoid touching anything in the Outbox:
var folder = this.explorer.CurrentFolder;var outbox = this.Application.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);bool isOutbox = folder.EntryID == outbox.EntryID;Marshal.ReleaseComObject(outbox);// Don't touch items in the Outbox at allif (isOutbox) return;
Preliminary checks show that it seems to do the trick, but I need to test it fully before releasing an update. (I also need to do something better with the ribbon controls when viewing the Outbox than just ignoring them!)