保存时出现错误MAPI_E_OBJECT_CHANGED()RDOEmail

时间:2017-01-06 17:34:25

标签: outlook outlook-redemption

调用Save()两次raice MAPI_E_OBJECT_CHANGED错误。奇怪的是,如果我在网格上选择另一封邮件并返回然后再次选择第一封邮件并执行它可以正常工作的操作。这只发生在imap帐户中。 代码:

public void UpdateMailObject(bool linked)
{
    Outlook._Application outlookApplication = null;
    Redemption.RDOMail rdoEmail = null;
    Redemption.RDOSession rdoSession = null;
    RDOFolder folder = null;
    RDOStores stores = null;
    RDOStore store = null;
    RDOStore unwStore = null;
    Outlook.Explorer outlookExplorer = null;
    Outlook.MailItem selectedMail = null;
    try
    {
        outlookApplication = new Outlook.Application();
        rdoSession = new Redemption.RDOSession();
        object MAPIOBJECT = outlookApplication.Session.GetType().InvokeMember("MAPIOBJECT", BindingFlags.GetProperty, null,
                outlookApplication.Session, null);
        rdoSession.MAPIOBJECT = MAPIOBJECT;
        outlookExplorer = outlookApplication.ActiveExplorer();
        selectedMail = outlookExplorer.Selection.OfType<Outlook.MailItem>().FirstOrDefault();

        RDOMail rdoMailAux = rdoSession.GetRDOObjectFromOutlookObject(selectedMail, true) as RDOMail;
        folder = rdoMailAux.Parent as RDOFolder;
        Marshal.ReleaseComObject(rdoMailAux);
        string storeId = folder.StoreID;
        stores = rdoSession.Stores;
        store = stores.GetStoreFromID(storeId);
        unwStore = stores.UnwrapStore(store);
        rdoEmail = unwStore.GetMessageFromID(selectedMail.EntryID, null);

        string sGUID = PS_PUBLIC_STRINGS.ToString("B");
        int iID = rdoEmail.GetIDsFromNames(sGUID, GMLINK);

        if (iID != 0)
        {
            rdoEmail.set_Fields(iID, linked);
        }

        rdoEmail.Save();
    }
    finally
    {
        if (outlookApplication != null)
        {
            Marshal.ReleaseComObject(outlookApplication);
        }
        if (folder != null)
        {
            Marshal.ReleaseComObject(folder);
        }
        if (stores != null)
        {
            Marshal.ReleaseComObject(stores);
        }
        if (store != null)
        {
            Marshal.ReleaseComObject(store);
        }
        if (unwStore != null)
        {
            Marshal.ReleaseComObject(unwStore);
        }
        if (rdoEmail != null)
        {
            Marshal.ReleaseComObject(rdoEmail);
        }
        if (outlookExplorer != null)
        {
            Marshal.ReleaseComObject(outlookExplorer);
        }

        if (rdoSession != null)
        {
            Marshal.ReleaseComObject(rdoSession);
        }
    }
}

0 个答案:

没有答案