Platform SDK: Exchange Server |
The HrMailboxLogon and HrMailboxLogoff functions are designed to simplify the task of performing basic mailbox management. The sample code in the following section shows how to implement the two functions listed.
To log on to a mailbox as a privileged service
The full source code for this sample application is located in MBLSAMPL.C. For clarity, error handling is not included in this code sample.
// -------------------------------------------------------------- // Opening a mailbox using privileged access - without error detection. // -------------------------------------------------------------- AnyFunction() { LPTSTR lpszProfileName = "Admin Profile"; LPTSTR lpszPassword = NULL; LPTSTR lpszServer = "/O=Organization/OU=Site/CN=Servers/CN=ServerName/CN=NULL"; LPTSTR lpszMailbox = "/O=Organization/OU=Site/CN=Recipients/CN=MailboxName"; LPMAPISESSION lplhSession = NULL; LPMDB lpMDB = NULL; // Ptr to default msg store interface. LPMDB lpMailboxMDB = NULL; // Ptr to any another's msg store interface. ULONG cbeid = 0; LPENTRYID lpeid = NULL; MAPIInitialize( NULL); MAPILogonEx( 0, lpszProfileName, lpszPassword, MAPI_NEW_SESSION | MAPI_LOGON_UI | MAPI_EXTENDED, &lplhSession); HrMAPIFindDefaultMsgStore( lplhSession, &cbeid, &lpeid); MAPICALL( lplhSession)->OpenMsgStore( lplhSession, 0, cbeid, lpeid, NULL, MDB_NO_DIALOG | MAPI_BEST_ACCESS, &lpMDB); HrMailboxLogon( lplhSession, lpMDB, lpszMsgStoreDN, lpszMailboxDN, &lpMailboxMDB); // Now lpMailboxMDB contains the MAPI interface needed to access the mail box requested. ... }