My Outlook is connected to an Exchange account that accepts emails for multiple domains. When I open up the emails, Outlook always displays my name in the To field, but doesn’t show which email (i.e. which domain) the mail was actually sent to.
I decided that manually checking the mail headers for this information was a dumb way to do things, so I wrote a little macro to automate this little task. Hopefully some of you out there will find it useful.
Installation Instructions
- Press Alt+F11
- On the left hand side, expand the tree until you see ThisOutlookSession. Make sure ThisOutlookSession is highlighted.
- Paste the code from below
- Close the Visual Basic window
- Attach the new macro to a toolbar item. The way to do this varies with your version of Outlook. For example, in Outlook 2007:
- Open any email
- Press the down arrow on the right side of the quick access toolbar
- Select “More Commands”
- In the “Choose Commands From” dropdown, select “Macros”
- Add the macro to the right hand side
- (Optional) Change the icon by highlighting the macro and selecting Modify.
- You can add the macro either to the “view email” screen as I explained above, or to the toolbar of the main inbox screen.
Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
Sub WhoWasThisMailSentTo() Dim olSelection As Outlook.Selection Set olSelection = Application.ActiveExplorer.Selection If olSelection.Count = 1 Then Dim oItem As Object Set oItem = olSelection(1) If (oItem.MessageClass = "IPM.Note") Then Dim RegEx As Object, oMatches As Object Dim Headers As String Dim oMail As Outlook.MailItem Set oMail = oItem Headers = oMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E") Set RegEx = CreateObject("VBScript.RegExp") RegEx.Pattern = "To: (.+)" RegEx.IgnoreCase = True Set oMatches = RegEx.Execute(Headers) If (oMatches.Count >= 1) Then MsgBox "This message was sent to: " & oMatches(0).SubMatches(0) Else MsgBox "Error: Could not fine the To header." End If Else MsgBox "Error: This macro only works on emails." End If Else MsgBox "Error: This macro doesn't work if you select more than one item." End If End Sub |
Added Dec 17: To ensure the macro isn’t blocked by the Outlook macro security settings, follow the instructions in this article to sign your own macros.