1
votes

I'm using ExchangeServer 2010 SP2 and Outlook 2013

First I'm saving a Mail to the Draft folder using EWS

EmailMessage.Save()

After that I'm trying to open the mail via Interop but I'm getting a COMException that the item doesn't exist

        Outlook.Application app = new Outlook.Application();            
        Outlook.NameSpace mapi = app.GetNamespace("MAPI");            
        Outlook.MAPIFolder draftFolder = mapi.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts);

        //Custom function to get EntryID
        string entryId = GetMessageId(email,IdFormat.HexEntryId);
        string storeId = draftFolder.StoreID;

        MailItem item = null;

        try
        {
            item = mapi.GetItemFromID(entryId, storeId);
        }
        catch (COMException)
        {
            //Item not found
        }

Is there any way to force Outlook to sync the Draft folder with the Exchange server?

I have used Session.SendAndRecieve(true)

but it doesn't show any effect and I can't find any other Interop functions doing the desired thing.

EDIT: When disabling Cache-Mode everything runs fine but as soon as I turn it on I have no clue how to force it to get the Message

Thank you very much!

1

1 Answers

0
votes

You can either

  1. wait until the sync finishes - use Namespace.SyncObjects collection, retrieve the first SyncObject object, call SyncObject.Start and wait for the SyncObject.SyncEnd event to fire.

  2. On the Extended MAPI level (C++ or Delphi) or Redemption (it wraps Extended MAPI and can be used in any language), open the message in the online mode by using the MAPI_NO_CACHE (0x200) flag (IMsgStore::OpenEntry in Extended MAPI or RDOStore.GetMessageFromID in Redemption).