HowTo: Convert Exchange-based email address into SMTP email address

Posted on Friday, May 8th, 2009 at 11:54 am by Dmitry Kostochko

It would be true to say “get” rather than “convert”. There could be only one right way – to use Extended MAPI. Another method is described in the MSDN article: How to retrieve alternate e-mail addresses by using CDO, but we will not see into this approach, because CDO is optional in Outlook 2003 and is absent completely in Outlook 2007.

So, Microsoft Exchange Server can operate with email address types such as Exchange, SMTP, X.400, Microsoft Mail, etc. By default, the Address property of the Mail.Recipient object returns just an Exchange type address, for example this one:

/O=ORGANIZATION_NAME /OU=EXCHANGE_GROUP /CN=RECIPIENTS /CN=USER_NAME

To get other address types, we need to find the recipient in the Outlook address book by using the IAddrBook.ResolveName method, then reach the IMailUser interface with the IAddrBook.OpenEntry method and get the PR_EMS_AB_PROXY_ADDRESSES property. The code below gets the Address property from NameSpace.CurrentUser.AddressEntry, checks the address type and obtains the SMTP address if it is of the Exchange type:


Private Sub CommandBarButton1_Click(ByVal sender As System.Object) _
    Handles CommandBarButton1.Click

    ' Outlook Explorer button
    Dim ns As Outlook._NameSpace = OutlookApp.Session
    If ns IsNot Nothing Then
        Try
            Dim currentUser As Outlook.Recipient = ns.CurrentUser
            If currentUser IsNot Nothing Then
                Try
                    Dim entry As Outlook.AddressEntry = _
                        currentUser.AddressEntry
                    If entry IsNot Nothing Then
                        Try
                            Dim smtpAddress As String = String.Empty
                            ' Exchange address
                            If (entry.Type = "EX") Then
                                smtpAddress = GetSMTPAddress( _
                                    entry.Address)
                            Else
                                smtpAddress = entry.Address
                            End If
                            MessageBox.Show("SMTP Address:" + _
                                Environment.NewLine + _
                                smtpAddress)
                        Finally
                            Marshal.ReleaseComObject(entry)
                        End Try
                    End If
                Finally
                    Marshal.ReleaseComObject(currentUser)
                End Try
            End If
        Finally
            Marshal.ReleaseComObject(ns)
        End Try
    End If
End Sub

I will not publish the whole code of the GetSMTPAddress method right here, because it is rather huge. You can download VB.NET and C# samples with source code, including the declaration of Extended MAPI interfaces, types, tags and properties via the links below.

That’s all for now, have a nice weekend!

Available downloads:

The sample add-ins below were developedĀ on Add-in Express 2009 for Office and .net

C# sample Outlook add-in for VS 2005
VB.NET sample Outlook add-in for VS 2005

4 Comments to “HowTo: Convert Exchange-based email address into SMTP email address”

  • Ryan Farley says:

    The problem with doing it this way (that I have found the hard way) is that if the user is offline and does not have an offline address book OR the Exchange address is an unpublished address/user then this will fail and cause Outlook to prompt the user with a “Check Names” dialog, asking the user to choose someone else, etc – rather than just resolve it using the PR_EMAIL field for the AddressEntry.

  • Dmitry Kostochko says:

    You are right, it can also be done that way. Thank you.

  • Himz says:

    I am having the same problem for the users that are not published. How can fix this?
    I am not sure how to use PR_EMAIL field to fix this problem. I don’t see any such field in the AddressEntry.

  • Dmitry Kostochko says:

    I have just modified and uploaded both samples. Now they can get an smtp address by using the PR_SMTP_ADDRESS (or RP_EMAIL) property without accessing the Outlook address book.

Post a comment

  • Sign In
  • SITEMAP