How to get the EMail Address from a contact

Apr 30, 2014 at 3:24 AM
I have written a Mapi application which would read couple of properties from a give contact. Most of the properties like PR_HOME_TELEPHONE_NUMBER , PR_HOME2_TELEPHONE_NUMBER , PR_MOBILE_TELEPHONE_NUMBER are working fine.

However, I could not get any property for getting the mailid(e.g. PR_EMAIL_ADDRESS). But after checking in couple of machine, I found that email address is getting stored in following tags
  • 0x805A
  • 0x8060
  • 0x8079
But, today we found that in some machines email address is getting store in following tags
  • 0x8037
  • 0x807B
I guess, I am not doing something right(for getting the email address). Is there a better way to get the email address(for a given contact)?

Any help is appreciated.

Apr 30, 2014 at 1:21 PM
You're looking at the property tag of a named property, which you can identify because the tag is > 0x8000. You need to be looking at the named property name. In MFCMAPI, that's a different column.
May 2, 2014 at 5:19 AM
Thanks Griffin,
I shall check this, and let you know
May 2, 2014 at 11:42 AM
Edited May 2, 2014 at 11:43 AM
Hi Griffin,

I am using following code

void CMapiSession::GetContacts(LPMAPIFOLDER lpFolder)
HRESULT         hr              = S_OK;
LPMAPITABLE     lpContentsTable = NULL;
LPSRowSet               sRows = NULL;
enum {ePR_GIVEN_NAME ,                      
    ePR_EMAIL1_ORIGINAL_DISPLAY_NAME ,              
            ePR_BUSINESS_TELEPHONE_NUMBER ,                 

//These tags represent the message information we would like to pick up
static SizedSPropTagArray(NUM_COLS,sptCols) = { NUM_COLS,
                                                                        PR_GIVEN_NAME ,
                                                                        PR_EMAIL1_ORIGINAL_DISPLAY_NAME ,
                                                                         PR_BUSINESS_TELEPHONE_NUMBER };

hr = lpFolder->GetContentsTable(0, &lpContentsTable);

hr = HrQueryAllRows(    lpContentsTable,
                                 (LPSPropTagArray) &sptCols,
                                NULL,//restriction...we're not using this parameter
                                NULL,//sort order...we're not using this parameter

for (unsigned int iIndex = 0; iIndex < sRows -> cRows; iIndex++)
    //do somethinbg

After spending couple of hours(reading and debugging MFCMAPI), following is my understanding
  • Since there is no fixed tag for "PR_EMAIL1_ORIGINAL_DISPLAY_NAME"(unlike PR_BUSINESS_TELEPHONE_NUMBER) we can NOT make use of GetContentsTable. Is this understanding right(or is there a workaround)?
  • We need to use GetProps(), and then use GetNamesFromIDs() to solve this problem.
Appreciate your feedback.

May 2, 2014 at 1:14 PM
You're trying to get a named property. You need to use GetIDsFromNames to map the name of the property to the property tag you can use to retrieve the property. I would study this before proceeding:

Once you understand named properties, here's the Contact documentation that will tell you which named properties to fetch:
May 5, 2014 at 2:56 AM
Thanks Griffin. I do appreciate your help.
May 19, 2014 at 10:45 AM
I have used your code from the following link

And it worked like a charm :-)