How to: Map a Display Name to an E-mail Address
Outlook Developer Reference |
This topic shows a code sample in Visual Basic for Applications (VBA) that takes a display name and tries to map it to an e-mail address known to the messaging system in the current session.
For each Outlook session, the transport provider defines a set of address book containers that the messaging system can deliver messages to. Each address book container corresponds to an address list in Outlook. If a display name is defined in the set of address book containers, the display name can be resolved in the current session and there exists an entry in an address list that maps to this display name. Note that entries in an address list can be of various types, including an Exchange user and Exchange distribution list.
In this code sample, the function ResolveDisplayNameToSMTP
uses the display name "Dan Wilson" as an example. It first tries to verify that the display name is defined in an address list by creating a Recipient object based on this display name and then calling Recipient.Resolve. If the name is resolved, then ResolveDisplayNameToSMTP
uses the AddressEntry object that is mapped to the Recipient object to further obtain the type and, if possible, the e-mail address:
- If the type of the AddressEntry object is an Exchange user,
ResolveDisplayNameToSMTP
calls AddressEntry.GetExchangeUser to obtain the corresponding ExchangeUser object. ExchangeUser.PrimarySmtpAddress provides the e-mail address that maps to the display name. - If the AddressEntry object is an Exchange distribution list,
ResolveDisplayNameToSMTP
calls AddressEntry.GetExchangeDistributionList to obtain an ExchangeDistributionList object. ExchangeDistributionList.PrimarySmtpAddress provides the e-mail address that maps to the display name.
|