ID: Q183249
The information in this article applies to:
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.
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.
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().
#include <MAPIUTIL.H>
#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 : kbAPI kbEDK kbMsg kbMAPI100 MAPIIAB
Version : WINDOWS:1.0,5.0,5.5
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 2, 1998