Microsoft KB Archive/183249

= HOWTO: How to Modify Recipient's Alias Through Extended MAPI =

Article ID: 183249

Article Last Modified on 8/18/2005

-

APPLIES TO


 * Microsoft Exchange Development Kit 5.5
 * Microsoft Exchange Server 2003 Software Development Kit
 * Microsoft Messaging Application Programming Interface

-



This article was previously published under Q183249



SUMMARY
This article explains how to programmatically modify the alias attribute of a Microsoft Exchange Server recipient using Extended Messaging Application Programming Interface (MAPI) and Exchange Developers Kit (EDK) calls.



MORE INFORMATION
The code below demonstrates step-by-step how to accomplish the task. After getting a valid session and getting the address book, you open the entry with the MAPI_MODIFY flag. After that, you get the attributes and search through them looking for the one you want to change; in this case the recipient's alias 0x3A00001E. Once found, you modify and save the change.

Step-by-Step Example
Following the steps above you should have the following pseudo-code:
 * 1) Initialize MAPI with MAPIInitialize.
 * 2) Logon to MAPI with MAPILogonEx.
 * 3) Get the address book through IMAPISession::OpenAddressBook.
 * 4) "Create" an entryid to the recipient with the EDK function, HrCreateDirEntryIdEx.
 * 5) Open the entry by using the OpenEntry call.
 * 6) Get the attributes with IMAPIProp::GetProps.
 * 7) Change the attribute with IMAPIProp::SetProps.
 * 8) Save changes using IMAPIProp::SaveChanges.

Sample Code
#include   #include "edkutils.h"

#define FAILURE -1

int main( void ) {     LPADRBOOK lpAdrBook; LPMAPISESSION pSession = NULL; HRESULT hRes = 0; ULONG  ulObjType = 0; LPMAPIPROP lpEntry  = NULL; FLAGS flFlags = MAPI_ALLOW_OTHERS | MAPI_EXTENDED; ULONG cbeid; LPENTRYID peid = NULL; ULONG ulValues; LPSPropValue pPropValues = NULL; // Recipient name. char* szExName ="/o=BIGOPERA/ou=TURANDOT/cn=Recipients/cn=RobertoC"; char* szNewalias = "CarlosA";

// Initialize MAPI. hRes = MAPIInitialize( NULL ); if ( FAILED( hRes ) ) throw (FAILURE);

// Logon to MAPI. hRes = MAPILogonEx( 0, "Galileo Galilei", NULL,                         flFlags, &pSession ); if ( FAILED( hRes ) ) throw (FAILURE);

// Open the address book. hRes=pSession->OpenAddressBook(0, 0, MAPI_ACCESS_MODIFY,                                     &lpAdrBook ); if ( FAILED( hRes ) ) throw (FAILURE);

// Obtain the entry id for the recipient object. hRes = HrCreateDirEntryIdEx(lpAdrBook, szExName, &cbeid, &peid); if ( FAILED( hRes ) ) throw (FAILURE);

// Now open the recipient object. hRes = lpAdrBook->OpenEntry( cbeid, peid, NULL,                                  MAPI_MODIFY, &ulObjType,                                  (LPUNKNOWN*) &lpEntry ); if ( FAILED( hRes ) ) throw (FAILURE);

// Get the properties. hRes = ((IMAPIProp *) lpEntry)->GetProps( NULL,                                               0,                                                &ulValues,                                                &pPropValues ); if ( FAILED( hRes ) ) throw (FAILURE);

// Modify alias name for recipient. for ( ULONG ul = 0; ul < ulValues; ul++ ) {

if ( 0x3A00001E == pPropValues[ul].ulPropTag ) {

// Modify property. pPropValues[ul].Value.lpszA = szNewalias;

// Set properties. hRes = ((IMAPIProp *) lpEntry)->SetProps( 1,                                                      &pPropValues[ul],                                                        NULL ); if ( FAILED( hRes ) ) throw (FAILURE);

// Save changes. hRes = ((IMAPIProp *) lpEntry)->SaveChanges( 0 ); if ( FAILED( hRes ) ) throw (FAILURE);

break; }     }     return 0; }

Keywords: kbhowto kbapi kbmsg kbcode KB183249

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.