当 Outlook 处于缓存 Exchange 模式时,在远程服务器上打开存储

适用于:Outlook 2013 | Outlook 2016

本主题包含 C++ 中的代码示例,演示如何在Microsoft Outlook 2010或Microsoft Outlook 2013处于缓存 Exchange 模式时使用 MDB_ONLINE 标志在远程服务器上打开消息存储。

缓存 Exchange 模式允许 Outlook 2010 和 Outlook 2013 使用用户邮箱的本地副本,而 Outlook 2010 或 Outlook 2013 与远程 Exchange 服务器上的用户邮箱远程副本保持联机连接。 当 Outlook 2010 或 Outlook 2013 在缓存 Exchange 模式下运行时,默认情况下,登录到同一会话的任何 MAPI 解决方案也会连接到缓存的邮件存储区。 访问的任何数据和所做的任何更改都是针对邮箱的本地副本进行的。

客户端或服务提供商可以在调用 IMAPISession::OpenMsgStore 时,通过在 ulFlags 参数中设置MDB_ONLINE位来覆盖与本地消息存储的连接并打开远程服务器上的存储。 在该会话的远程服务器上成功打开存储后,可以使用 IMAPISession::OpenEntry 打开远程存储上的项目或文件夹。

不能在同一 MAPI 会话中同时以缓存模式和非缓存模式打开 Exchange 存储。 如果已经打开缓存的邮件存储区,或者必须使用此标记关闭存储,或打开新的 MAPI 会话,可以使用此标记在远程服务器上打开 Exchange 存储。

下面的代码示例演示如何使用 ulFlags 参数中设置的 MDB_ONLINE 标志调用 IMAPISession::OpenMsgStore 以打开远程服务器上的默认存储。

HRESULT HrRemoteMessageStore( 
    LPMAPISESSION lpMAPISession, 
    LPMDB* lppMDB) 
{ 
    HRESULT hRes = S_OK; 
    LPMAPITABLE pStoresTbl = NULL; 
    SRestriction sres = {0}; 
    SPropValue spv = {0}; 
    LPSRowSet pRow = NULL; 
    LPMDB lpTempMDB = NULL; 
    enum {EID,NUM_COLS}; 
    static SizedSPropTagArray(NUM_COLS,sptCols) = {NUM_COLS, 
        PR_ENTRYID, 
    }; 
 
    //Obtain the table of all the message stores that are available 
    hRes = lpMAPISession->GetMsgStoresTable(0, &pStoresTbl); 
     
    if (SUCCEEDED(hRes) && pStoresTbl) 
    { 
        //Set up restrictions for the default store 
        sres.rt = RES_PROPERTY;                                  //Comparing a property 
        sres.res.resProperty.relop = RELOP_EQ;                   //Testing equality 
        sres.res.resProperty.ulPropTag = PR_DEFAULT_STORE;       //Tag to compare 
        sres.res.resProperty.lpProp = &spv;                      //Prop tag and value to compare against 
     
        spv.ulPropTag = PR_DEFAULT_STORE;                        //Tag type 
        spv.Value.b   = TRUE;                                    //Tag value 
     
        //Convert the table to an array that can be stepped through 
        //Only one message store should have PR_DEFAULT_STORE set to true, so that only one will be returned 
        hRes = HrQueryAllRows( 
            pStoresTbl,                                          //Table to query 
            (LPSPropTagArray) &sptCols,                          //Which columns to obtain 
            &sres,                                               //Restriction to use 
            NULL,                                                //No sort order 
            0,                                                   //Max number of rows (0 means no limit) 
            &pRow);                                              //Array to return 
 
        if (SUCCEEDED(hRes) && pRow && pRow->cRows) 
        {     
            //Open the first returned (default) message store 
            hRes = lpMAPISession->OpenMsgStore( 
                NULL,                                                //Window handle for dialogs 
                pRow->aRow[0].lpProps[EID].Value.bin.cb,             //size and... 
                (LPENTRYID)pRow->aRow[0].lpProps[EID].Value.bin.lpb, //value of entry to open 
                NULL,                                                //Use default interface (IMsgStore) to open store 
                MAPI_BEST_ACCESS | MDB_ONLINE,                       //Flags 
                &lpTempMDB);                                         //Pointer to put the store in 
            if (SUCCEEDED(hRes) && lppMDB) lppMDB* = lpTempMDB; 
        } 
    } 
    FreeProws(pRow); 
    if (pStoresTbl) pStoresTbl->Release(); 
 
    return hRes; 
}

另请参阅