In a Windows application, calling OpenMsgStore function is throwing error when I am trying to open the default primary store for ‘Outlook’ 2016 Outlook profile only when the user is logged off. When the user is logged in, all the MAPI functions work successfully.
HRESULT hr = MAPILogonEx(0,
const_cast<LPTSTR>((LPCTSTR)m_strProfileTemplate), NULL,
MAPI_EXTENDED | MAPI_NEW_SESSION | MAPI_NO_MAIL | MAPI_UNICODE,
&m_pSession);
SRestriction sres;
SPropValue spv;
LPSRowSet pStores = NULL;
hr = m_pSession->GetMsgStoresTable(0, &pStoresTable);
sres.rt = RES_PROPERTY;
sres.res.resProperty.relop = RELOP_EQ;
sres.res.resProperty.ulPropTag = PR_DEFAULT_STORE;
sres.res.resProperty.lpProp = &spv;
spv.ulPropTag = PR_DEFAULT_STORE;
spv.Value.b = TRUE;
hr = HrQueryAllRows(pStoresTable,(LPSPropTagArray) &sptCols,&sres,NULL,0,&pStores);
ULONG flags = MDB_WRITE| MDB_NO_MAIL;
hr = m_pSession->OpenMsgStore(NULL,pStores->aRow[0].lpProps[0].Value.bin.cb,
(LPENTRYID)pStores->aRow[0].lpProps[0].Value.bin.lpb,
NULL,
flags | MDB_ONLINE,
&pPrimaryMessageStore);
The call for OpenMsgStore
fails with the MAPI_E_FAILONEPROVIDER
error when the user is logged off from the system and the service executes the above code.
However this function is successful when user is logged in to system.
How does the MAPI work if the user, trying to access outlook as a scheduled service is logged off from the system?
2
Try including the MAPI_NT_SERVICE
flag to the MAPILogonEx
call.
That means the caller is running as a Windows service. Callers that are not running as a Windows service should not set this flag; callers that are running as a service must set this flag.
AFAIK if OAuth is used, MAPI system cannot find the cached credentials and opening the message store fails.
4