Outlook 2013 Hybrid Searching and OOM COM Exception


  • Synopsis: Our Outlook VSTO add-in has been experiencing the following exception when trying to call mailItem.parent or on certain items in the Outbox when the user is simultaneously performing a server-side search for mail in the mailbox.   Our add-in supports Outlook 2003 - 2013 and this problem only occurs in Outlook 2013.

    System.Runtime.InteropServices.COMException (0x8004010F): Exception from HRESULT: 0x8004010F

    Description: It appears that the problem is related to the new cached exchange mode feature of Outlook 2013.  It supports a hybrid mode in the sense that you can store some of your email locally and older messages on the server.  With this feature enabled, if you perform a search in Outlook for a message you can scroll to the bottom of the search results to access a link to search for more results by searching messages on the server.  

    In Outlook’s settings there are search options as well.  It defaults to searching the entire mailbox when you perform searches from the inbox.  Our VSTO add-in may receive a COM exception from Outlook when attempting to perform certain operations on mail items in the Outbox (like mailItem.Save() or mailItem.parent) while a user is performing a server-side search where it searches the entire mailbox thereby effectively putting a sort of “lock” on those items even if they don’t match the search criteria.  Even if the add-in were to attempt to retry sending those emails they will still experience the error until the search results are dismissed.

    In my testing thus far the problem can be avoided by either turning off cached exchange mode, or setting cached exchange mode to cache all items, or changing Outlook search settings to include results only from the current folder and not the mailbox so that the Outbox is not searched.

    This smells to me like an Outlook bug.  Is there anything I can do programmatically to avoid this problem maybe by determining that a search is in progress and thereby halt any programmatic email processing until the search is complete and the search results are dismissed?

    • Edited by mcoburn Tuesday, October 29, 2013 9:19 PM
    Tuesday, October 29, 2013 9:13 PM

All replies

  • The error is MAPI_E_NOT_FOUND. I don't think there is any way for you check if a search is running.

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 30, 2013 2:17 PM
  • I created a simple sample add-in that demonstrates the problem.  All you need to do is:

    - Using Visual Studio 2012 create a new Outlook 2013 Add-in project using the project template

    - In ThisAddIn_Startup register to receive the ItemAdd event for the outbox

    - In the ItemAdd event handler try to save the email (e.g. mailItem.Save();)

    With that add-in running perform the following steps to reproduce the COM exception:

    - Ensure that your Exchange account is configured to use Cached Exchange Mode and set to keep up to 12 months of mail offline (this is an Outlook 2013 feature).

    - Start Outlook

    - Under the File menu choose Options, Search Tab (in left-hand navigation), and check the "Current folder.  Current mailbox when searching from the inbox" checkbox (this is default setting by the way)

    - Press OK to save the Outlook settings

    - Select the Inbox and then type some text to search for an email

    - If you scroll to the bottom of the search results (granted that you have older emails on the Exchange server that aren't cached locally) you will have the option to view more results by clicking the "More" link.

    - Once you click this link leave the search results alone and don't dismiss them

    - Now compose a new email to yourself (you can leave the email body blank and just provide a subject)

    - Set the deferred delivery date of the email to at least a few minutes into the future.  This can be done by selecting the Options tab, Delay Delivery, checking the "Do not deliver before" checkbox and setting the corresponding date and time fields to a time in the future.

    - Now send the email and notice that the sample add-in will experience a COM exception when simply trying to perform a mailItem.Save() OOM call.  I also know that trying to access the item's parent will also fail in the same way (e.g. mailItem.Parent).

    Note that this can happen when the email is sent while the server-side search is actively being performed or after it has been performed but before dismissing the search results by clicking the X near the search critieria.  This doesn't happen if cached exchange mode is off, or it is set to cache "all" items, or if you don't click the "More" link to view the messages on the server, or if you set Outlook's search options to not search the mailbox and just the current folder instead.

    Our add-in defers the delivery of emails that are sent so that it can process the outbox items and upload attachments before allowing the email to actually be delivered.  So it is important that this case works for us and it has worked quite well from Outlook 2003 - Outlook 2010.

    I have Outlook 2013 (15.0.4535.1006) MSO (15.0.4535.1507) 32-bit and Exchange 2007 SP3 Version 8.3 (Build 83.6).

    Wednesday, October 30, 2013 5:52 PM
  • You should never access any messages in the Outbox folder - once a message is submitted, it belongs to a spooler. You are only allowed to release your reference to it.

    Why exactly are you monitoring messages in the Outbox folder instead of Sent Items?

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 30, 2013 5:55 PM
  • We want to be able to strip the attachments from the email, upload them to our server, and provide links in the email body to download the attachments from the server.  We don't want to send the email until the attachments have been uploaded.  Large attachments may take a while to upload so we wan't to keep the email from being delivered until then.  Our add-in provides progress bars and such to track the uploading of the attachments if they desire to view that information.  Once the attachments have been uploaded then the add-in will turn off the deferred delivery date and programmatically resend the email.
    Wednesday, October 30, 2013 6:06 PM
  • Then you need to handle the Application.ItemSend event, which is synchronously called before the message is actually submitted.

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 30, 2013 6:12 PM
  • I do handle that event actually.  That is where I set the deferred delivery date to 10 years in the future.  Then we have an outbox monitor which finds the email in the outbox via ItemAdd or a timer and uploads the attachments, manipulates the email, and resends it.

    The only other option I see is to have Application.ItemSend move the email to a different folder other than the outbox (or to our own custom folder) and not send it.  Then we later process the email in that other folder and then send it at that point.

    Wednesday, October 30, 2013 6:18 PM