How to: Get the Email Address of a Contact Item

Office 2013 and later

Last modified: June 25, 2012

Applies to: Outlook

This topic shows how to obtain the value of a named property that represents the email address of an Microsoft Outlook 2010 or Microsoft Outlook 2013 Contact item.

You can associate up to three email addresses with a Contact item in Outlook 2010 and Outlook 2013. Each email address corresponds to a property of the Outlook 2010 or Outlook 2013ContactItem object in the Outlook 2010 and Outlook 2013 object models. Internal to Outlook 2010 and Outlook 2013, the email address also corresponds to a MAPI named property. For example, the first email address of a contact corresponds to the Email1Address property of the ContactItem in the Outlook 2010 and Outlook 2013 object models, and the Outlook 2010 and Outlook 2013 internal named PidLidEmail1EmailAddress Canonical Property.

To obtain the value of an email address of a contact item, you can use the PropertyAccessor object of the Outlook 2010 or Outlook 2013 object model, or first use IMAPIProp::GetIDsFromNames to obtain the property tag of the named property, and then specify this property tag in IMAPIProp::GetProps to get the value. When calling IMAPIProp::GetIDsFromNames, specify the appropriate values for the MAPINAMEID structure pointed at by the input parameter lppPropNames. The following code sample shows how to obtain the first email address of a specified contact, lpContact, using GetIDsFromNames and GetProps.

HRESULT HrGetEmail1(LPMESSAGE lpContact) 
{ 
    HRESULT hRes = S_OK; 
    LPSPropTagArray lpNamedPropTags = NULL; 
    MAPINAMEID NamedID = {0}; 
    LPMAPINAMEID lpNamedID = &NamedID; 
    NamedID.lpguid = (LPGUID)&PSETID_Address; 
    NamedID.ulKind = MNID_ID; 
    NamedID.Kind.lID = dispidEmailEmailAddress; 
 
    hRes = lpContact->GetIDsFromNames( 
           1,  
           &lpNamedID,  
           NULL,  
           &lpNamedPropTags); 
 
    if (SUCCEEDED(hRes) && lpNamedPropTags) 
    { 
        SPropTagArray sPropTagArray; 
 
        sPropTagArray.cValues = 1; 
        sPropTagArray.aulPropTag[0] = CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[0],PT_STRING8); 
        LPSPropValue lpProps = NULL; 
        ULONG cProps = 0; 
 
        hRes = lpContact->GetProps( 
               &sPropTagArray, 
               NULL, 
               &cProps, 
               &lpProps); 
        if (SUCCEEDED(hRes) &&  
            1 == cProps &&  
            lpProps &&  
            PT_STRING8 == PROP_TYPE(lpProps[0].ulPropTag) && 
            lpProps[0].Value.lpszA) 
        { 
            printf("Email address 1 = \"%s\"\n",lpProps[0].Value.lpszA); 
        } 
        MAPIFreeBuffer(lpProps); 
        MAPIFreeBuffer(lpNamedPropTags); 
     } 
     return hRes; 
}
Show: