Show AD Username in Outlook

Does anyone know of a way to show a user's AD logon/username in Outlook? When I get an email from a user, I often will have to look up their username name.

If Outlook showed me that information, it would save quite a bit of searching every day. If it helps, I am running Outlook 2013 and Exchange 2007.
LVL 22
Joseph MoodyBlogger and wearer of all hats.Asked:
Who is Participating?
David LeeConnect With a Mentor Commented:
Here's my solution.  It works by looking up each message sender in Active Directory and retrieving their account name.  It then adds a user property called "Username" to that message and sets it to the account name.  You can then add a new column to your view to see the username field.

Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Press ALT+F11 to open the Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Click the diskette icon on the toolbar to save the changes
6.  Close the VB Editor
7.  Click File and select Options
8.  Click Trust Center
9. Click the Trust Center Settings button
10. Click Macro Settings
11. Change Macro Settings to "Notifications for all macros"
12. Click OK
13. Click OK
14. Close Outlook
15. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim arrEID As Variant, varEID As Variant, olkItm As Object, olkPrp As Object, olkExu As Object, strUsr As String
    On Error Resume Next
    arrEID = Split(EntryIDCollection, ",")
    For Each varEID In arrEID
        Set olkItm = Session.GetItemFromID(varEID)
        If olkItm.Class = olMail Then
            Set olkExu = olkItm.Sender.GetExchangeUser
            If TypeName(olkExu) = "Nothing" Then
                strUsr = "Unknown"
                strUsr = GetUsernameFromAlias(olkExu.Alias)
            End If
            Set olkPrp = olkItm.UserProperties.Add("Username", olText, True)
            olkPrp.value = strUsr
            Set olkPrp = Nothing
        End If
    On Error GoTo 0
    Set olkItm = Nothing
    Set olkExu = Nothing
End Sub

Function GetUsernameFromAlias(strAls As String) As String
    Dim adoCon As Object, adoRec As Object, objDSE As Object, strDNC As String, strSrc As String
    Set objDSE = GetObject("LDAP://RootDSE")
    strDNC = objDSE.get("defaultnamingcontext")
    strSrc = "'LDAP://" & strDNC & "'"
    Set adoCon = CreateObject("ADODB.Connection")
    adoCon.Provider = "ADsDSOObject"
    adoCon.CursorLocation = 3
    adoCon.Open "ADSI"
    Set adoRec = adoCon.Execute("SELECT samAccountName FROM " & strSrc & " Where objectClass='user' AND objectCategory='Person' AND mailNickname='" & strAls & "'")
    If Not adoRec.BOF And Not adoRec.EOF Then
        GetUsernameFromAlias = adoRec.Fields("samAccountName").value
        GetUsernameFromAlias = "Not Found"
    End If
    Set adoRec = Nothing
    Set adoCon = Nothing
    Set objDSE = Nothing
End Function

Open in new window

try this
there is no other way or option to change the address view..

David LeeCommented:
Hi, Jmoody10.

How about a macro that displays that information?  If a macro is acceptable, then I can post the code and instructions for using it.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Joseph MoodyBlogger and wearer of all hats.Author Commented:
A Macro would be probably work!
David LeeCommented:
The macro would look the username up and add it to a custom property.  You could then customize your view to show that property.  Keep in mind that this will only work for messages you receive from folks inside your organization.  It won't work for messages you receive from anyone outside of your organization.
Joseph MoodyBlogger and wearer of all hats.Author Commented:
This is wonderful!!!
David LeeCommented:
Cool.  I'm glad you like it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.