How could I get programmatically (with a VBA Excel macro) access to the Outlook properties of a single contact for whom I have the User Principal Name?
I am interested in particular to the tab labelled "E-mail Addresses".
I managed to get the PrimarySMTP property, but I would like to get the list of all addresses that are listed there. The 'alias' property only gives me one entry, while there are several others.
This is what I did to get the distribution list memberships:
Dim objExchUsr As ExchangeUser
Dim myolApp As Outlook.Application
Dim myNameSpace As Namespace
Dim MyAddrList As AddressList
Dim myRecipient As Outlook.Recipient
Dim oDistListEntries As Outlook.AddressEntries
Dim oAE As Outlook.AddressEntry
Set myolApp = CreateObject("Outlook.Application")
Set myNameSpace = myolApp.GetNamespace("MAPI")
Set MyAddrList = myNameSpace.addressLists("Global Address List")
Set myRecipient = myNameSpace.CreateRecipient(strDisplayname)
myRecipient.Resolve
If myRecipient.Resolved Then
Set objExchUsr = myRecipient.AddressEntry.GetExchangeUser
Set oDistListEntries = objExchUsr.GetMemberOfList
For Each oAE In oDistListEntries
If oAE.AddressEntryUserType = olExchangeDistributionListAddressEntry Then
<Do something with the distribution lists: not relevant to this problem>
End If
Next
End If
While with this code I get the information shown in the tab 'Member Of' of the Outlook Properties, my problem is how to get the information that is shown in the tab 'E-mail Addresses'
Thank you in advance
CodePudding user response:
You need to read the PR_EMS_AB_PROXY_ADDRESSES
MAPI property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x800F101F"
) using AddressEntry.PropertyAccessor.GetProperty
. You will get back an array of proxy addresses prefixed with the address type (e.g. "EX:" or "SMTP:")
CodePudding user response:
Here is the code you could use:
Const PR_EMS_AB_PROXY_ADDRESSES As String = _
"http://schemas.microsoft.com/mapi/proptag/0x800F101F"
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
addresses = _
NS.CurrentUser.AddressEntry.PropertyAccessor.GetProperty(PR_EMS_AB_PROXY_ADDRESSES)