Microsoft KB Archive/248357: Difference between revisions

From BetaArchive Wiki
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&gt;
<pre class="codesample">#include <stdio.h>
#include &quot;mapiutil.h&quot;
#include "mapiutil.h"
#include &quot;emsabtag.h&quot;
#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 = &quot;Alias&quot;;
     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,
             &amp;lpSession);
             &lpSession);
     if (FAILED(hr)) goto UnInit;
     if (FAILED(hr)) goto UnInit;


     hr = lpSession-&gt;OpenAddressBook(0,NULL,0,&amp;lpAddrbk);
     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*) &amp;pAdrList);
     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 *)&amp;(pAdrList-&gt;aEntries[0].rgPropVals));
             (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 -&gt; aEntries[0].rgPropVals,
     ZeroMemory ( pAdrList -> aEntries[0].rgPropVals,
             7 * sizeof(SPropValue) );
             7 * sizeof(SPropValue) );


     // How many recipients to resolve.
     // How many recipients to resolve.
     pAdrList-&gt;cEntries = 1;
     pAdrList->cEntries = 1;
     pAdrList-&gt;aEntries[0].cValues = 2L;
     pAdrList->aEntries[0].cValues = 2L;


     pAdrList-&gt;aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
     pAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
     pAdrList-&gt;aEntries[0].rgPropVals[0].Value.lpszA =  lpszDisplayName;
     pAdrList->aEntries[0].rgPropVals[0].Value.lpszA =  lpszDisplayName;
     pAdrList-&gt;aEntries[0].rgPropVals[1].ulPropTag = PR_ADDRTYPE;
     pAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_ADDRTYPE;
     pAdrList-&gt;aEntries[0].rgPropVals[1].Value.lpszA = &quot;SMTP&quot;;
     pAdrList->aEntries[0].rgPropVals[1].Value.lpszA = "SMTP";


     hr = lpAddrbk -&gt; ResolveName (0L, 0L, NULL, pAdrList );
     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-&gt;aEntries[0].rgPropVals[i].ulPropTag == PR_ENTRYID)  
       if (pAdrList->aEntries[0].rgPropVals[i].ulPropTag == PR_ENTRYID)  
       {
       {
             printf(&quot;EntryID: %u\n&quot;, pAdrList-&gt;aEntries[0].rgPropVals[i].Value.ul);
             printf("EntryID: %u\n", pAdrList->aEntries[0].rgPropVals[i].Value.ul);
              
              
             sBin.cb = pAdrList-&gt;aEntries[0].rgPropVals[i].Value.bin.cb;
             sBin.cb = pAdrList->aEntries[0].rgPropVals[i].Value.bin.cb;
             sBin.lpb = pAdrList-&gt;aEntries[0].rgPropVals[i].Value.bin.lpb;
             sBin.lpb = pAdrList->aEntries[0].rgPropVals[i].Value.bin.lpb;


             hr = lpAddrbk-&gt;OpenEntry(sBin.cb,
             hr = lpAddrbk->OpenEntry(sBin.cb,
                         (LPENTRYID)sBin.lpb,
                         (LPENTRYID)sBin.lpb,
                         NULL,  
                         NULL,  
                         0,
                         0,
                         &amp;ulObjType,
                         &ulObjType,
                         (LPUNKNOWN*)&amp;pMailUser);
                         (LPUNKNOWN*)&pMailUser);
             if (FAILED(hr)) goto Cleanup;
             if (FAILED(hr)) goto Cleanup;


             hr = pMailUser-&gt;GetProps((LPSPropTagArray)&amp;sptOneItem,
             hr = pMailUser->GetProps((LPSPropTagArray)&sptOneItem,
                                         0,  
                                         0,  
                                         &amp;cValues,
                                         &cValues,
                                         &amp;lpPropValue);
                                         &lpPropValue);
              
              
             if (hr &amp; MAPI_W_ERRORS_RETURNED)
             if (hr & MAPI_W_ERRORS_RETURNED)
             {
             {
                 printf(&quot;Warning in GetProps...\n&quot;);
                 printf("Warning in GetProps...\n");
                 goto Cleanup;
                 goto Cleanup;
             }
             }
Line 164: Line 164:
             if (HR_FAILED(hr))
             if (HR_FAILED(hr))
             {
             {
                 printf(&quot;GetProps failed...\n&quot;);
                 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-&gt;Value.MVszA.cValues; j++)
             for (j = 0; j < lpPropValue->Value.MVszA.cValues; j++)
             {
             {
                 printf(&quot;%s\n&quot;, lpPropValue-&gt;Value.MVszA.lppszA[j]);
                 printf("%s\n", lpPropValue->Value.MVszA.lppszA[j]);
             }
             }


Line 179: Line 179:
     MAPIFreeBuffer((LPVOID)pAdrList);
     MAPIFreeBuffer((LPVOID)pAdrList);
Cleanup0:
Cleanup0:
     if (pMailUser) pMailUser-&gt;Release();
     if (pMailUser) pMailUser->Release();
     if (lpAddrbk) lpAddrbk-&gt;Release();
     if (lpAddrbk) lpAddrbk->Release();
     lpSession-&gt;Logoff(0, 0, 0);
     lpSession->Logoff(0, 0, 0);
     if (lpSession) lpSession-&gt;Release();
     if (lpSession) lpSession->Release();
UnInit:
UnInit:
     MAPIUninitialize();
     MAPIUninitialize();

Latest revision as of 13:50, 21 July 2020

Knowledge Base


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