How to: Get the E-mail Address of a Contact Item

Last modified: October 10, 2010

Applies to: Office 2010 | Outlook 2010 | Visual Studio

This topic shows how to obtain the value of a named property that represents the e-mail address of an Microsoft Outlook 2010 Contact item.

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

To obtain the value of an e-mail address of a contact item, you can use the PropertyAccessor object of the Outlook 2010 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 e-mail 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( 
    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( 
        if (SUCCEEDED(hRes) &&  
            1 == cProps &&  
            lpProps &&  
            PT_STRING8 == PROP_TYPE(lpProps[0].ulPropTag) && 
            printf("Email address 1 = \"%s\"\n",lpProps[0].Value.lpszA); 
     return hRes;