HOWTO: Modifying Settings of MS Exchange Transport ProviderLast reviewed: December 2, 1997Article ID: Q170225 |
The information in this article applies to:
SUMMARYThis article explains how to programmatically change the values of the Microsoft Exchange Transport Provider and review those changes after they have been committed.
MORE INFORMATIONChanging the settings for the Microsoft Exchange Server service provider can be broken into two phases: creating and configuring a profile and modifying some or all of the settings of the Microsoft Exchange Server service provider.
Creating and Configuring a ProfileFirst follow the steps listed below to create and configure a profile. (These steps can be found on the Microsoft Developer Network (MSDN) in the article "Creating and Configuring a Profile.")
Modifying Settings of Service ProviderThe steps above helped you to create and configure a generic profile. In the second phase you will modify some or all of the settings of the Microsoft Exchange Server service provider. (These steps can also be found on MSDN in the article "Creating a Profile through MAPI.") When you reach the step in which the MAPI IMsgServiceAdmin::ConfigureMsgService method is called, specify the following information in the lpProps parameter. This parameter is a pointer to an SPropValue structure containing the values of the properties to display to the user in the property sheet.
SummaryFollowing the steps above you should have code that is comparable to the pseudo-code below. (NOTE: The following pseudo-code uses PR_UNRESOLVE_XXX properties to configure the profile. Using the properties mentioned above generally fail to configure the service as expected.)
Sample CodeFollowing is one possible implementation of the pseudo-code. It is only a sample, but it meets the design goals of changing various settings of the Microsoft Exchange Service Provider and displaying the results of those changes:
HRESULT ChangeMSESPSettings ( LPSTR lpszProfile, HWND hWnd ) { HRESULT hRes = S_OK; LPPROFADMIN pProfAdmin = NULL; LPSERVICEADMIN pSvcAdmin = NULL; LPMAPITABLE pMsgSvcTable = NULL; LPSRowSet pRows = NULL; SPropValue rgval[2]; LPMAPISESSION pSession = NULL; SRestriction sres; SPropValue pSvcProps; enum {iSvcName, iSvcUID, cptaSvc}; SizedSPropTagArray (cptaSvc, sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID }; for ( int i = 0; i < 2; i++) ZeroMemory ( &rgval[i], sizeof ( SPropValue ) ); // Get IProfAdmin interface pointer if ( FAILED ( hRes = MAPIAdminProfiles ( 0L, &pProfAdmin ) ) ) goto Quit; // Create a new profile -- IProfAdmin::CreateProfile() // If the attempt to create the profile fails, remove the profile if ( FAILED ( hRes = pProfAdmin -> CreateProfile ( lpszProfile, "", (ULONG)hWnd, 0L ) ) ) { hRes = pProfAdmin -> DeleteProfile ( lpszProfile, 0L ); goto Quit; } // Get IMsgServiceAdmin interface pointer if ( FAILED ( hRes = GetAdminService ( &pSvcAdmin, NULL ) ) ) goto Quit; // Add a message service to the newly created profile if (FAILED(hRes = pSvcAdmin->CreateMsgService ( "MSEMS", "Microsoft Exchange", (ULONG)hWnd, 0L ) ) ) goto Quit; // Get the message service table of the Message service if ( FAILED ( hRes = pSvcAdmin->GetMsgServiceTable(0L, &pMsgSvcTable) ) ) goto Quit; // Get the row from the message service table which represents the // Microsoft Exchange Server service provider sres.rt = RES_CONTENT; sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING; sres.res.resContent.ulPropTag = PR_SERVICE_NAME; sres.res.resContent.lpProp = &pSvcProps; pSvcProps.ulPropTag = PR_SERVICE_NAME; pSvcProps.Value.lpszA = "MSEMS"; if ( FAILED ( hRes = HrQueryAllRows ( pMsgSvcTable, (LPSPropTagArray)&sptCols, &sres, NULL, 0, &pRows ) ) ) goto Quit; // Set the values for PR_PROFILE_UNRESOLVED_NAME and // PR_PROFILE_UNRESOLVED_SERVER rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_NAME; rgval[0].Value.lpszA = "<user name>"; rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER; rgval[1].Value.lpszA = "<server name>"; if ( FAILED ( hRes = pSvcAdmin -> ConfigureMsgService( (LPMAPIUID) pRows -> aRow->lpProps[iSvcUID].Value.bin.lpb, 0, NULL, 2, rgval ) ) ) hRes = pProfAdmin -> DeleteProfile ( lpszProfile, 0L ); // Logon to a new MAPI session using new profile -- MAPILogonEx() if ( SUCCEEDED ( hRes = MAPILogonEx ( ( ULONG )hWnd, lpszProfile, "", MAPI_NEW_SESSION | MAPI_NO_MAIL, &pSession ) ) ) { // Release and reuse IMsgService and IMAPITable // objects. pSvcAdmin -> Release ( ); pMsgSvcTable -> Release ( ); FreeProws ( pRows ); pSvcAdmin = NULL; pMsgSvcTable = NULL; pRows = NULL; // Get new IMsgServiceAdmin interface pointer hRes = pSession -> AdminServices ( 0L, &pSvcAdmin ); // Get the Message service table if(FAILED(hRes = pSvcAdmin->GetMsgServiceTable ( 0L, &pMsgSvcTable ) ) ) goto Quit; // Find the row that represents the MSEMS message service if ( FAILED ( hRes = HrQueryAllRows (pMsgSvcTable, (LPSPropTagArray)&sptCols, &sres, NULL, 0, &pRows ) ) ) goto Quit; // Open the property sheet for the service if ( FAILED ( hRes = pSvcAdmin -> ConfigureMsgService( (LPMAPIUID) pRows -> aRow -> lpProps[iSvcUID].Value.bin.lpb, 0, SERVICE_UI_ALLOWED | SERVICE_UI_ALWAYS, 5, rgval) ) ) goto Quit; } Quit: if ( hRes ) hRes = pProfAdmin -> DeleteProfile ( lpszProfile, 0L ); if ( pMsgSvcTable ) { FreeProws( pRows ); pRows = NULL; pMsgSvcTable -> Release ( ); pMsgSvcTable = NULL; } if ( m_pProfAdmin ) { if ( hRes == MAPI_E_NO_ACCESS ) pProfAdmin -> DeleteProfile ( lpszProfile, 0L ); } if ( pSvcAdmin ) { pSvcAdmin -> Release ( ); pSvcAdmin = NULL; } if ( pSession ) { pSession -> Logoff ( (ULONG)m_hWnd, MAPI_LOGOFF_SHARED, 0L ); pSession -> Release ( ); pSession = NULL; } return hRes; } STDMETHODIMP GetAdminService ( LPSERVICEADMIN * lppSvcAdmin, LPMAPISESSION m_pSession) { HRESULT hRes = S_OK; LPSERVICEADMIN lpSvcAdmin = NULL; If(NULL!=m_pSession) hRes = m_pSession -> AdminServices ( 0L, &lpSvcAdmin ); else hRes = MAPIAdminProfiles(0L, &lpSvcAdmin) if ( SUCCEEDED ( hRes ) ) *lppSvcAdmin = lpSvcAdmin; return hRes; }This code results in the messaging service property sheet for Microsoft Exchange Server service provider being displayed with the server and mailbox properties set for the profile.
Keywords : kbcode EMAPI ExchExt MAPIIXP Version : WINDOWS:1.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |