Outlooking on Outlook - your answers are here

Outlook Global Technical Support Team Blog

How to programmatically read additional mailboxes from an existing mail profile

How to programmatically read additional mailboxes from an existing mail profile

  • Comments 1
  • Likes

Reading additional mailboxes from a given e-mail profile is much simpler than adding them. After retrieving all installed providers for the MSEMS service, just loop thru all providers and search for the ones with PR_PROFILE_TYPE set to the value 2.

This is documented here:
http://msdn.microsoft.com/en-us/library/office/cc815597.aspx

For each 'delegate store' simply read the following properties (which are later required if you want to add this mailbox to a different/new.... e-mail profile):

PR_DISPLAY_NAME
PR_PROFILE_MAILBOX
PR_PROFILE_SERVER
PR_PROFILE_SERVER_DN


Here's a code snippet which shows on how to enumerate the installed providers for the MSEMS service:

Disclaimer 
This code is sample code. these samples are provided "as is" without warranty of any kind. Microsoft further disclaims all implied warranties including without limitation any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the samples remains with you. in no event shall Microsoft or its suppliers be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the samples, even if Microsoft has been advised of the possibility of such damages. Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you.

 

 // Enumeration for convenience.
 enum {iDispName, iSvcName, iSvcUID, cptaSvc};

 // This structure tells HrQueryAllRows what columns we want returned.
 SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc,
       PR_DISPLAY_NAME,
       PR_SERVICE_NAME,
       PR_SERVICE_UID };
 
 // This structure tells HrQueryAllRows what columns we want returned.
 // Information when reading the installed provider services
 static SizedSPropTagArray(3, sptProvt) = {3, {  PR_DISPLAY_NAME,
       PR_RESOURCE_TYPE,
       PR_PROVIDER_UID} };

 // Get an IProfAdmin interface.
 hRes = MAPIAdminProfiles(0, &lpProfAdmin);// Pointer to new IProfAdmin
 if (FAILED(hRes)) goto error_handler;
 
 // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
 hRes = lpProfAdmin->AdminServices(lpszProfile, "", NULL, 0, &lpSvcAdmin);// Pointer to new IMsgServiceAdmin.
 if (FAILED(hRes))
 { 
  printf("Can't open Mail profile %s\n", lpszProfile);
  goto error_handler;
 }
 
 // We now need to get the entry id for the Exchange service.
 // First, we get the Message service table.
 hRes = lpSvcAdmin->GetMsgServiceTable(0, &lpMsgSvcTable);// Pointer to table
 if (FAILED(hRes)) goto error_handler;
 
 // Set up restriction to query table.
 sres.rt = RES_PROPERTY;
 sres.res.resProperty.relop = RELOP_EQ;
 sres.res.resProperty.ulPropTag = PR_SERVICE_NAME;
 sres.res.resProperty.lpProp = &SvcProps;

 SvcProps.ulPropTag = PR_SERVICE_NAME;
 SvcProps.Value.lpszA = "MSEMS";

 // Query the table to get the entry for the Exchange message service.
 hRes = HrQueryAllRows(lpMsgSvcTable, (LPSPropTagArray)&sptCols, &sres, NULL, 0, &lpSvcRows);
 if (FAILED(hRes)) goto error_handler;

 // Test if exchange service was found
 if (lpSvcRows->cRows == 0)
 {
  printf("MSEMS Service not found in Mail profile %s\n", lpszProfile);
  goto error_handler;
 }

 // Get a provider admin pointer.
 hRes = lpSvcAdmin->AdminProviders((LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb, 0, &lpProvAdmin);
 if (FAILED(hRes)) goto error_handler;
  
 hRes = lpProvAdmin->GetProviderTable(NULL, &pMTProviders);
 if (FAILED(hRes)) goto error_handler;
   
 hRes = HrQueryAllRows(pMTProviders, (LPSPropTagArray)&sptProvt, NULL, NULL, 0, &pProvRows);
 if (FAILED(hRes)) goto error_handler;

 

At this point, the rowset pProvRows contains all installed provider services for the MSEMS service and you can loop thru and read the properties.

Comments
  • How to programmatically read additional mailboxes from an existing mail profile
    thank you

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment