Hi,
Thank you for the posting. As you indicated, you have a question about the
display name in the sender field in the view pane.
The MailItem object in the Outlook object model contains a SenderName
property, but this property may not contain a fully qualified e-mail
address that uniquely identifies the sender of the mail message. The
SenderName property contains the string value of the sender's display name.
If the sender is an Exchange user, the display name generally contains that
sender's first and last name. If the user is not an Exchange user, there is
no guarantee what the string value of the SenderName property will be. The
SenderName property may contain the first and last name of the sender, the
sender's SMTP address, or a combination of both, such as the following:
<FirstName> (
[email protected])
The functionality of this property is by design, and it has been so since
Outlook 97. The inability to directly return a fully qualified e-mail
address is a limitation of the Outlook object model.
You can use one of the following approaches to retrieve fully qualified
e-mail addresses from e-mail messages.
Create a Reply by Using the Object Model
----------------------------------------
You can create a reply e-mail message and then retrieve the Address
property of the recipient in the Recipients collection of the new reply
message. After you have the address, you can discard the reply. The
following Microsoft Visual Basic for Applications (VBA) code illustrates
how to retrieve the fully qualified e-mail address of an open e-mail
message:
Sub GetEmailAddressReply()
Dim objItem As MailItem
Dim objReply As MailItem
Dim objRecips As Outlook.Recipients
Dim objRecip As Outlook.Recipient
Set objItem = Application.ActiveInspector.CurrentItem
Set objReply = objItem.Reply
Set objRecips = objReply.Recipients
For Each objRecip In objRecips
Debug.Print objRecip.Address
Next
Set objItem = Nothing
Set objReply = Nothing
Set objRecip = Nothing
End Sub
Use Collaboration Data Objects (CDO) 1.2x Library
-------------------------------------------------
You can retrieve a sender's address by using the Sender property in the CDO
1.2<x> object library. The following CDO automation code retrieves the
Address property from the sender:
Sub GetAddressFromCDO()
Dim objSession As MAPI.Session
Dim objInboxMsgs As MAPI.Messages
Dim objMsg As MAPI.Message
Dim strAddress As String
Const g_PR_SMTP_ADDRESS_W = &H39FE001F
Set objSession = CreateObject("MAPI.Session")
objSession.Logon NewSession:=False
Set objInboxMsgs = objSession.Inbox.Messages
For Each objMsg In objInboxMsgs
Debug.Print objMsg.Subject
strAddress = objMsg.Sender.Address
' If the e-mail sender is an Exchange user, the e-mail address
' will return as an X400 address and not an SMTP address.
' If the Address property does not return a fully qualified
' address (for example, containing an @), try the &H39FE001F MAPI
' IMPORTANT: This property is not documented on MSDN.
If Not InStr(strAddress, "@") Then
On Error Resume Next
strAddress = objMsg.Sender.Fields(g_PR_SMTP_ADDRESS_W).value
End If
Debug.Print strAddress
Debug.Print
Next
objSession.Logoff
Set objMsg = Nothing
Set objInboxMsgs = Nothing
Set objSession = Nothing
End Sub
Retrieve an SMTP Address from Alternate Exchange Addresses
----------------------------------------------------------
An Exchange property contains all the available addresses for a recipient
in the organization. To retrieve the fully qualified address of a recipient
in an Exchange organization, you can retrieve this property by using CDO
1.2<x>, and then parse the contents to find the SMTP address.
The following VBA code retrieves the SMTP address of an Exchange user by
accessing the H800F101E MAPI property. Make sure that you reference the
Microsoft CDO 1.2<x> object library.
Sub RetrieveAlternateAddress()
Dim objSession As MAPI.Session
Dim objCDOMsg As MAPI.Message
Dim objAddEntry As MAPI.AddressEntry
Dim objField As MAPI.Field
Dim objMsg As MailItem
Dim strEntryID As String
Dim strStoreID As String
Dim strAddress As String
Dim fld
Set objSession = CreateObject("MAPI.Session")
On Error Resume Next
objSession.Logon NewSession:=False
Set objMsg = Application.ActiveInspector.CurrentItem
strEntryID = objMsg.EntryID
strStoreID = objMsg.Parent.StoreID
Set objCDOMsg = objSession.getMessage(strEntryID, strStoreID)
Set objAddEntry = objCDOMsg.Sender
If objAddEntry.Type = "EX" Then
Set objField = objAddEntry.Fields(&H800F101E)
For Each fld In objField.Value
If Left(fld, 5) = "SMTP:" Then
strAddress = Mid(fld, 6)
Debug.Print strAddress
Exit For
End If
Next
Else
Debug.Print objAddEntry.Address
End If
objSession.Logoff
Set objSession = Nothing
Set objAddEntry = Nothing
Set objCDOMsg = Nothing
Set objMsg = Nothing
Set objField = Nothing
End Sub
Hope the above information and suggestion helps and answers your question.
If anything is unclear or anything further we can help with from our side,
please let me know.
If you have any suggestion on Microsoft product, please go to the following
mswish web site to submit:
http://register.microsoft.com/mswish/suggestion.asp
We appreciate your input and look forward to building better products with
helpful ideas from our customers, such as you.
Sincerely,
Cherry Qian
MCSE2000, MCSA2000, MCDBA2000
Microsoft Partner Online Support
Get Secure! -
www.microsoft.com/security
====================================================
When responding to posts, please Reply to Group via your newsreader so
that others may learn and benefit from your issue.
====================================================
This posting is provided AS IS with no warranties, and confers no rights.