Display Address Entry Details for the Sender of a Message
The recipient of each mail message deliverable by a transport provider has an address entry in the provider's hierarchy of address books for the session. This topic describes how to programmatically display the address entry information of the sender of a mail item that is currently displayed in an inspector.
For the currently displayed mail item, use the PropertyAccessor object to determine the Entry ID of the sender.
Use the NameSpace.GetAddressEntryFromID method of the current session to return an AddressEntry object.
Use the AddressEntry.AddressEntryUserType property to determine the type of the AddressEntry, and then display the details accordingly:
- If the address entry is a contact item in the Outlook Contacts folder, or if the SMTP address of the sender matches an email address of one contact item in the default Contacts folder, then display the address entry information in a Contacts inspector. To match email addresses in the Contacts folder, use the Table object to do a quick filter on the ContactItem.Email1Address, ContactItem.Email2Address, and ContactItem.Email3Address properties of items in that folder.
- In all other cases, display the address entry information in the Email Properties dialog box.
Remarks
To run this code sample:
Open a mail message to have it displayed in the active inspector.
Place the code in the built-in ThisOutlookSession module.
Run the
TestAddressEntryDetails
procedure to display address entry details on the mail message in the active inspector:
Sub TestAddressEntryDetails()
Dim oMail As MailItem
Set oMail = Application.ActiveInspector.CurrentItem
DisplayAddressEntryDetails oMail
End Sub
Sub DisplayAddressEntryDetails(oM As MailItem)
Dim oPA As Outlook.PropertyAccessor
Dim oContact As Outlook.ContactItem
Dim oSender As Outlook.AddressEntry
Dim SenderID As String
'Create an instance of PropertyAccessor
Set oPA = oM.PropertyAccessor
'Obtain PidTagSenderEntryId and convert to string
SenderID = oPA.BinaryToString _
(oPA.GetProperty("https://schemas.microsoft.com/mapi/proptag/0x0C190102"))
'Obtain AddressEntry Object of the sender
Set oSender = Application.Session.GetAddressEntryFromID(SenderID)
'Examine AddressEntryUserType
If oSender.AddressEntryUserType = olOutlookContactAddressEntry Then
'Obtain ContactItem for AddressEntry
Set oContact = oSender.GetContact
oContact.Display
'Display details for Exchange or SMTP sender
Else
oSender.Details
End If
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.