EWS - Outlook 互操作同步

EWS - Outlook Interop Synchronize

我使用的是 ExchangeServer 2010 SP2 和 Outlook 2013

首先,我使用 EWS 将邮件保存到草稿文件夹

EmailMessage.Save()

之后我尝试通过 Interop 打开邮件 但我收到一个 COMException,指出该项目不存在

        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
        }

有没有办法强制 Outlook 将草稿文件夹与 Exchange 服务器同步?

我用过 Session.SendAndRecieve(true)

但它没有显示任何效果,而且我找不到任何其他 Interop 函数来做我想要的事情。

编辑:禁用缓存模式时一切正常,但一旦我打开它,我不知道如何强制它获取消息

非常感谢!

你可以

  1. 等到同步完成 - 使用 Namespace.SyncObjects 集合,检索第一个 SyncObject 对象,调用 SyncObject.Start 并等待 SyncObject.SyncEnd 事件开火。

  2. 在扩展 MAPI 级别(C++ 或 Delphi)或 Redemption (I am its author, 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 RDOStoreGetMessageFromID 在 Redemption 中。