I used Redemption (http://dimastr.com/redemption/home.htm) for develop my Outlook AddIn. When I try GetMessageFromId in STA-thread(!) at first time all good, but in next times i get MAPI_E_UNKNOWN_ENTRYID.
RDOSession rdoSession = null;.
rdoSession = new RDOSession();
if (rdoSession != null)
{
if (!rdoSession.LoggedOn)
rdoSession.Logon(Consts.ProfileName);
if (rdoSession.LoggedOn)
{
for (int c = 1; c <= rdoStoresCnt; c++)
{
/* other code */
RDOMail mail = null;
try
{
mail = rdoSession.GetMessageFromID(entryID);
/* other code */
}
catch (Exception ex)
{
if (mail != null) Marshal.ReleaseComObject(mail); mail = null;
}
finally
{
if (mail != null) Marshal.ReleaseComObject(mail); mail = null;
}
}
}
}
What am I doing wrong?
MAPI_E_UNKNOWN_ENTRYID
means the current MAPI session (created by calling RDOSession.Logon
) does not know which MAPI provider is supposed to handle the specified entry id because (most likely) the provider has not been loaded yet in that session and did nto have a chance to register its set of entry ids with the MAPI system in the session.
You can try to specify the store entry id when calling GetMessageFromId
(Redemption will open the specified store first and call IMsStore::OpenEntry
instead of IMAPISession::OpenEntry
), but the real solution is avoid creating a brand new MAPI session at all - since your code is inside Outlook, there is already the MAPI session used by Outlook: simply set the RDOSession.MAPIOBJECT
property to Namespace.MAPIOBJECT
from Outlook. Do not call RDOSession.Logoff
in that case.