Microsoft KB Archive/248357: Difference between revisions
m (Text replacement - "<" to "<") |
m (Text replacement - """ to """) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 64: | Line 64: | ||
This code needs to be linked with Mapi32.lib. | This code needs to be linked with Mapi32.lib. | ||
<pre class="codesample">#include <stdio.h | <pre class="codesample">#include <stdio.h> | ||
#include | #include "mapiutil.h" | ||
#include | #include "emsabtag.h" | ||
void main() | void main() | ||
Line 88: | Line 88: | ||
// replace with a user's alias or display name | // replace with a user's alias or display name | ||
char* lpszDisplayName = | char* lpszDisplayName = "Alias"; | ||
// Initialize MAPI Subsystem | // Initialize MAPI Subsystem | ||
Line 99: | Line 99: | ||
NULL, | NULL, | ||
MAPI_LOGON_UI | MAPI_NEW_SESSION, | MAPI_LOGON_UI | MAPI_NEW_SESSION, | ||
& | &lpSession); | ||
if (FAILED(hr)) goto UnInit; | if (FAILED(hr)) goto UnInit; | ||
hr = lpSession- | hr = lpSession->OpenAddressBook(0,NULL,0,&lpAddrbk); | ||
if (FAILED(hr)) goto Cleanup0; | if (FAILED(hr)) goto Cleanup0; | ||
// resolve name | // resolve name | ||
// Allocate memory for new SRowSet structure. | // Allocate memory for new SRowSet structure. | ||
hr = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) & | hr = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) &pAdrList); | ||
if (FAILED(hr)) goto Cleanup0; | if (FAILED(hr)) goto Cleanup0; | ||
Line 114: | Line 114: | ||
hr = MAPIAllocateBuffer(7 * sizeof(SPropValue), | hr = MAPIAllocateBuffer(7 * sizeof(SPropValue), | ||
(LPVOID FAR *)& | (LPVOID FAR *)&(pAdrList->aEntries[0].rgPropVals)); | ||
if (FAILED(hr)) goto Cleanup; | if (FAILED(hr)) goto Cleanup; | ||
// Zero out allocated memory. | // Zero out allocated memory. | ||
ZeroMemory ( pAdrList - | ZeroMemory ( pAdrList -> aEntries[0].rgPropVals, | ||
7 * sizeof(SPropValue) ); | 7 * sizeof(SPropValue) ); | ||
// How many recipients to resolve. | // How many recipients to resolve. | ||
pAdrList- | pAdrList->cEntries = 1; | ||
pAdrList- | pAdrList->aEntries[0].cValues = 2L; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[0].Value.lpszA = lpszDisplayName; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_ADDRTYPE; | ||
pAdrList- | pAdrList->aEntries[0].rgPropVals[1].Value.lpszA = "SMTP"; | ||
hr = lpAddrbk - | hr = lpAddrbk -> ResolveName (0L, 0L, NULL, pAdrList ); | ||
if (FAILED(hr)) goto Cleanup; | if (FAILED(hr)) goto Cleanup; | ||
Line 136: | Line 136: | ||
{ | { | ||
// look for entry id | // look for entry id | ||
if (pAdrList- | if (pAdrList->aEntries[0].rgPropVals[i].ulPropTag == PR_ENTRYID) | ||
{ | { | ||
printf( | printf("EntryID: %u\n", pAdrList->aEntries[0].rgPropVals[i].Value.ul); | ||
sBin.cb = pAdrList- | sBin.cb = pAdrList->aEntries[0].rgPropVals[i].Value.bin.cb; | ||
sBin.lpb = pAdrList- | sBin.lpb = pAdrList->aEntries[0].rgPropVals[i].Value.bin.lpb; | ||
hr = lpAddrbk- | hr = lpAddrbk->OpenEntry(sBin.cb, | ||
(LPENTRYID)sBin.lpb, | (LPENTRYID)sBin.lpb, | ||
NULL, | NULL, | ||
0, | 0, | ||
& | &ulObjType, | ||
(LPUNKNOWN*)& | (LPUNKNOWN*)&pMailUser); | ||
if (FAILED(hr)) goto Cleanup; | if (FAILED(hr)) goto Cleanup; | ||
hr = pMailUser- | hr = pMailUser->GetProps((LPSPropTagArray)&sptOneItem, | ||
0, | 0, | ||
& | &cValues, | ||
& | &lpPropValue); | ||
if (hr & | if (hr & MAPI_W_ERRORS_RETURNED) | ||
{ | { | ||
printf( | printf("Warning in GetProps...\n"); | ||
goto Cleanup; | goto Cleanup; | ||
} | } | ||
Line 164: | Line 164: | ||
if (HR_FAILED(hr)) | if (HR_FAILED(hr)) | ||
{ | { | ||
printf( | printf("GetProps failed...\n"); | ||
goto Cleanup; | goto Cleanup; | ||
} | } | ||
// loop through the proxy multivalue property | // loop through the proxy multivalue property | ||
for (j = 0; j < lpPropValue- | for (j = 0; j < lpPropValue->Value.MVszA.cValues; j++) | ||
{ | { | ||
printf( | printf("%s\n", lpPropValue->Value.MVszA.lppszA[j]); | ||
} | } | ||
Line 179: | Line 179: | ||
MAPIFreeBuffer((LPVOID)pAdrList); | MAPIFreeBuffer((LPVOID)pAdrList); | ||
Cleanup0: | Cleanup0: | ||
if (pMailUser) pMailUser- | if (pMailUser) pMailUser->Release(); | ||
if (lpAddrbk) lpAddrbk- | if (lpAddrbk) lpAddrbk->Release(); | ||
lpSession- | lpSession->Logoff(0, 0, 0); | ||
if (lpSession) lpSession- | if (lpSession) lpSession->Release(); | ||
UnInit: | UnInit: | ||
MAPIUninitialize(); | MAPIUninitialize(); |
Latest revision as of 13:50, 21 July 2020
Article ID: 248357
Article Last Modified on 8/25/2005
APPLIES TO
- Microsoft Messaging Application Programming Interface
This article was previously published under Q248357
SUMMARY
This article contains an Extended MAPI code sample that demonstrates how to access the PR_EMS_AB_PROXY_ADDRESSES property of the Mail-Recipient object. This multi-valued property contains the foreign system e-mail addresses (alternate e-mail addresses).
MORE INFORMATION
Microsoft Exchange Server supports the following types of addresses:
- Exchange
- Microsoft Mail
- Mac Mail
- X.400
- Internet(SMTP)
- Lotus cc:Mail
- Custom
The PR_EMAIL_ADDRESS property of the Mail-Recipient object returns the Exchange (EX) type e-mail address by default. To retrieve the other addresses, you can use the PR_EMS_AB_PROXY_ADDRESSES property.
Sample Code
This code needs to be linked with Mapi32.lib.
#include <stdio.h> #include "mapiutil.h" #include "emsabtag.h" void main() { HRESULT hr = S_OK; LPMAPISESSION lpSession = NULL; LPADRBOOK lpAddrbk = NULL; ULONG cbEID = 0L; LPBYTE lpEID = NULL; LPADRLIST pAdrList = NULL; SBinary sBin; ULONG cValues = 0; ULONG ulObjType = NULL; LPMAILUSER pMailUser = NULL; LPSPropValue lpPropValue = NULL; ULONG i, j; SizedSPropTagArray(1, sptOneItem) = {1, PR_EMS_AB_PROXY_ADDRESSES}; // replace with a user's alias or display name char* lpszDisplayName = "Alias"; // Initialize MAPI Subsystem hr = MAPIInitialize(NULL); if (S_OK != hr) return; // Logon to MAPI hr = MAPILogonEx(0, NULL, NULL, MAPI_LOGON_UI | MAPI_NEW_SESSION, &lpSession); if (FAILED(hr)) goto UnInit; hr = lpSession->OpenAddressBook(0,NULL,0,&lpAddrbk); if (FAILED(hr)) goto Cleanup0; // resolve name // Allocate memory for new SRowSet structure. hr = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) &pAdrList); if (FAILED(hr)) goto Cleanup0; // Zero out allocated memory. ZeroMemory ( pAdrList, CbNewSRowSet(1)); hr = MAPIAllocateBuffer(7 * sizeof(SPropValue), (LPVOID FAR *)&(pAdrList->aEntries[0].rgPropVals)); if (FAILED(hr)) goto Cleanup; // Zero out allocated memory. ZeroMemory ( pAdrList -> aEntries[0].rgPropVals, 7 * sizeof(SPropValue) ); // How many recipients to resolve. pAdrList->cEntries = 1; pAdrList->aEntries[0].cValues = 2L; pAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME; pAdrList->aEntries[0].rgPropVals[0].Value.lpszA = lpszDisplayName; pAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_ADDRTYPE; pAdrList->aEntries[0].rgPropVals[1].Value.lpszA = "SMTP"; hr = lpAddrbk -> ResolveName (0L, 0L, NULL, pAdrList ); if (FAILED(hr)) goto Cleanup; for (i = 0; i < 7; ++i) { // look for entry id if (pAdrList->aEntries[0].rgPropVals[i].ulPropTag == PR_ENTRYID) { printf("EntryID: %u\n", pAdrList->aEntries[0].rgPropVals[i].Value.ul); sBin.cb = pAdrList->aEntries[0].rgPropVals[i].Value.bin.cb; sBin.lpb = pAdrList->aEntries[0].rgPropVals[i].Value.bin.lpb; hr = lpAddrbk->OpenEntry(sBin.cb, (LPENTRYID)sBin.lpb, NULL, 0, &ulObjType, (LPUNKNOWN*)&pMailUser); if (FAILED(hr)) goto Cleanup; hr = pMailUser->GetProps((LPSPropTagArray)&sptOneItem, 0, &cValues, &lpPropValue); if (hr & MAPI_W_ERRORS_RETURNED) { printf("Warning in GetProps...\n"); goto Cleanup; } if (HR_FAILED(hr)) { printf("GetProps failed...\n"); goto Cleanup; } // loop through the proxy multivalue property for (j = 0; j < lpPropValue->Value.MVszA.cValues; j++) { printf("%s\n", lpPropValue->Value.MVszA.lppszA[j]); } } } Cleanup: MAPIFreeBuffer((LPVOID)pAdrList); Cleanup0: if (pMailUser) pMailUser->Release(); if (lpAddrbk) lpAddrbk->Release(); lpSession->Logoff(0, 0, 0); if (lpSession) lpSession->Release(); UnInit: MAPIUninitialize(); }
REFERENCES
For information on alternate e-mail addresses supported by Microsoft Exchange Server and how to retrieve the PR_EMS_AB_PROXY_ADDRESSES property using Collaboration Data Objects (CDO), please refer to the following article in the Knowledge Base:
196507 How To Retrieve Alternate E-mail Addresses Using CDO
Keywords: kbhowto kbmsg KB248357