HowTo: Convert Exchange-based email address into SMTP email address
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 ' Outlook 2010 If (Me.HostMajorVersion >= 14) Then smtpAddress = GetSMTPAddressViaOutlookObjectModel( _ entry) Else smtpAddress = GetSMTPAddress( _ entry.Address) End If 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.
Updated 5-Jul-2010: The samples were modified to support Outlook 2010 x86 and x64; the samples were rebuilt with Add-in Express 2010.
Updated 4-Jun-2018: It is possible to add an Exchange user to your local Address Book. This scenario (and solution) is discussed at https://www.add-in-express.com/forum/read.php?FID=5&TID=15007.
The sample add-ins below were developed on Add-in Express 2010 for Office and .net