Get the email address of a recipient

This example shows how to get the Simple Mail Transfer Protocol (SMTP) address of a recipient.

Example

In the following the code example, the GetSMTPAddressForRecipients method takes a MailItem object as an input argument and then displays the SMTP address of each recipient for that mail item. The method first retrieves the Recipients collection that represents the set of recipients specified for the mail item. For each Recipient in that Recipients collection, the method then obtains the PropertyAccessor object that corresponds to that Recipient object. Finally, the method uses the PropertyAccessor property to get the value of the MAPI property https://schemas.microsoft.com/mapi/proptag/0x39FE001E, which maps to the PR_SMTP_ADDRESS (PidTagSmtpAddress) property of the recipient.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void GetSMTPAddressForRecipients(Outlook.MailItem mail)
{
    const string PR_SMTP_ADDRESS =
        "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
    Outlook.Recipients recips = mail.Recipients;
    foreach (Outlook.Recipient recip in recips)
    {
        Outlook.PropertyAccessor pa = recip.PropertyAccessor;
        string smtpAddress =
            pa.GetProperty(PR_SMTP_ADDRESS).ToString();
        Debug.WriteLine(recip.Name + " SMTP=" + smtpAddress);
    }
}

See also