Emails being sent to an email alias

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Emails being sent to an email alias

Post by John Gray »

I imagine this applies to all versions of Outlook and maybe versions of Exchange.

I am trying to determine whether there is any mechanism, other than inspecting the message headers, to determine to which address an email has been sent.

Suppose I have a primary email address primary@domain.org.uk and an alias email address alias@domain.org.uk.

I cannot determine whether someone has sent an email to primary or to alias because, when I inspect the email in Outlook it has
To: My Name
which is a sort of hyperlink to the Properties, where the 'E-mail Addresses' tab contains
SMTP:primary@domain.org.uk
smtp:alias@domain.org.uk

Any ideas welcomed! Thanks
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Emails being sent to an email alias

Post by StuartR »

You can see who the email was sent to in the internet headers:
  • Outlook 2010 - open the email. File Properties, alternatively you could add Message Options... to the QAT
  • Outlook 2007 - right click the email in a folder view and select Message Options...
  • Outlook 2003 - right click the email in a folder view and select Options...
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Emails being sent to an email alias

Post by John Gray »

Thanks, but I said "other than inspecting the message headers"!
It seems amazing that Microsoft does not seem to provide a mechanism to the average user of determining this information...
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Emails being sent to an email alias

Post by StuartR »

John Gray wrote:...I said "other than inspecting the message headers"!
...
Sorry, I missed that. I agree, it is a pain. The approach I use for a similar problem is to receive each of these emails via a different Outlook account and then to use an inbox rule that files emails to each account in a different folder.
StuartR


JoeP
SilverLounger
Posts: 2048
Joined: 25 Jan 2010, 02:12

Re: Emails being sent to an email alias

Post by JoeP »

You could setup a rule that would inspect the message header. The Outlook user would not have to actually inspect the header. Some way or another the message header must be processed. Once the address is resolved to a name the message header is the only way to see the original "To" address.

Joe
Joe

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Emails being sent to an email alias

Post by jscher2000 »

So the next step is to write a little procedure that reads the headers for you and extracts the information. :smile:

I have done that for a while, but I do recall that at least as of Outlook 2000-2002 it was easier using the Outlook Redemption library.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Emails being sent to an email alias

Post by John Gray »

Thanks, chaps! In Outlook 2010 (at least) you can trap on specific words in the message header, and perhaps "run a script", but that's where my knowledge ends. (The environment at work is Outlook 2003/Exchange 2007.)

I would like to suffix the Subject line (or maybe the To line) with something like "(originally sent to alias@domain.org.uk)" but only in those instances where the email is sent to the alias address, and not to the primary address...

I will have a look at this Redemption library of yours!
John Gray

Venison is quiet deer, and quite dear.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Emails being sent to an email alias

Post by jscher2000 »

Actually, you might not need Redemption, if you don't mind a security prompt. Here is some code that uses the CDO library:

Code: Select all

Function getInternetHeaders(aMsg As Outlook.MailItem, strSpec As String) As String
' strSpec should be in a format such as "|From|Sender|Reply-To|"
If Trim(strSpec) = vbNullString Then
    getInternetHeaders = vbNullString
    Exit Function
ElseIf InStr(1, strSpec, "|") = 0 Then
    getInternetHeaders = vbNullString
    Exit Function
End If
' Retrieve Internet Headers into a string array
Dim strArray() As String
strArray = Split( _
                Replace(strInternetHeaders(aMsg), vbTab, vbNullString), _
                Chr(13) & Chr(10))
If UBound(strArray) = 0 Then    ' This probably is not useful
    Debug.Print "Probably not an Internet message"
    getInternetHeaders = vbNullString
    Exit Function
End If
' Create | delimited string of headers per the input specification
Dim intCounter As Integer, intColonPos As Integer, strOut As String, strField As String
strOut = strSpec
For intCounter = 0 To UBound(strArray)
    intColonPos = InStr(1, strArray(intCounter), ": ")
    If intColonPos > 0 Then
        strField = "|" & Left(strArray(intCounter), intColonPos - 1) & "|"
        If InStr(1, strOut, strField) Then
            strOut = Replace(strOut, strField, "|" & Mid(strArray(intCounter), intColonPos + 2) & "|")
        End If
    End If
Next
getInternetHeaders = strOut
End Function

Function strInternetHeaders(aMsg As Outlook.MailItem) As String
' Adapted from http://www.slovaktech.com/code_samples.htm#InternetHeaders
' Generates a security prompt !!
Dim strID As String
strID = aMsg.EntryID    ' Retrieve a pointer usable in CDO

' Uses late binding to CDO 1.21 (CDO.DLL)
Dim objMessage As Object
Const CdoPR_TRANSPORT_MESSAGE_HEADERS = &H7D001E

'' Set up a CDO Session using a piggy-back login
'Set objCDO = CreateObject("MAPI.Session")
'objCDO.Logon "", "", False, False

' Now get the item as a CDO Message and retrieve/return message headers field
Set objMessage = objCDOSession.GetMessage(strID)
' Watch for errors generated by internal Exchange messages
On Error Resume Next
strInternetHeaders = objMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value
If Err.Number <> 0 Then
    If InStr(1, Err.Description, "MAPI_E_NOT_FOUND") = 0 Then
        Debug.Print "Unexpected error: " & Err.Description
    End If
    Err.Clear
End If
On Error GoTo 0

' Clean up CDO objects
'objCDO.Logoff
Set objMessage = Nothing
'Set objCDO = Nothing
End Function
Edit: On further thought, if this is going to be called by an Outlook rule, you don't want a security prompt.

This example using Redemption is quite ancient, so I'm not sure it's useful, but I think it worked back then...

Code: Select all

Sub ShowHeaders()
' Requires Outlook Redemption from http://www.dimastr.com/redemption/ to
'  access the headers
Dim msg As Outlook.MailItem
If Inspectors.Count > 0 Then
    ' Use the ActiveInspector, hopefully it's a mail message!
    Set msg = ActiveInspector.CurrentItem
Else
    ' Use the message selected in the list, if any
    If ActiveExplorer.Selection.Count = 0 Then
        MsgBox "Please select a mail message and try again.", _
            vbCritical + vbOKOnly, "ShowHeaders Error"
        Exit Sub
    End If
    Set msg = ActiveExplorer.Selection.Item(1)
End If
' Declare variables and constants
Dim strHeaders As String
Dim utils As Object                     ' for Redemption
Const PrInternetHeaders = &H7D001E      ' for Redemption
' Create objects
' Late binding - no Reference needed
Set utils = CreateObject("Redemption.MAPIUtils")
' Use Redemption to retrieve the Internet Headers
strHeaders = utils.HrGetOneProp(msg.MAPIOBJECT, PrInternetHeaders)
' Clean up Redemption objects; very important!!!
utils.CleanUp
If Not (utils Is Nothing) Then Set utils = Nothing
' Clean up other object references
If Not (msg Is Nothing) Then Set msg = Nothing
' Display headers
Debug.Print strHeaders
If Len(strHeaders) > 1024 Then
    MsgBox strHeaders, vbInformation, "First 1024 Bytes of Message Headers"
Else
    MsgBox strHeaders, vbInformation, "Message Headers"
End If
End Sub
Last edited by jscher2000 on 08 Feb 2011, 20:06, edited 1 time in total.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Emails being sent to an email alias

Post by John Gray »

Thanks, Jefferson! All I need to know now is where to locate it and how to invoke it - this is all new to me!
John Gray

Venison is quiet deer, and quite dear.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Emails being sent to an email alias

Post by jscher2000 »

John Gray wrote:Thanks, Jefferson! All I need to know now is where to locate it and how to invoke it - this is all new to me!
Do you just need the "To:" header, or do you need to search other parts?

I wonder whether the more basic rule approach of "with specific words in the recipient's address" wouldn't be more efficient? But then I guess that wouldn't let you edit the subject line. A rule could assign it to a category, for what it's worth...

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Emails being sent to an email alias

Post by John Gray »

I've tried a couple of rules, the first finding "specific words in the message header" and the second "specific words in the recipient's address", but since they don't work on "abuse@" (which is the alias I used, and whose message is sitting in my InBox) my guess is that Rules only apply to the Resolved email address (viz. the primary email address) not that in the message headers under "To: abuse@mydomain.com"... Is this correct?
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Emails being sent to an email alias

Post by StuartR »

John Gray wrote:...Rules only apply to the Resolved email address (viz. the primary email address) not that in the message headers under "To: abuse@mydomain.com"... Is this correct?
That is the conclusion I came to when I tried to do something very similar.

That is why I suggested using multiple accounts within Outlook and filtering on the account.
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Emails being sent to an email alias

Post by John Gray »

Thanks, Stuart - when someone leaves I usually move their email address to become an alias of someone who has stayed, to mop up residual emails, and I delete the original Exchange mailbox. Looks as though I will simply have to do an Outlook Forward from the leaver's mailbox to the continuing member of staff's - provided that the server can do this and it's not a 'client-side' operation which needs Outlook to be open on a PC...
John Gray

Venison is quiet deer, and quite dear.

PJ_in_FL
5StarLounger
Posts: 1090
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Emails being sent to an email alias

Post by PJ_in_FL »

(edited after seeing this is being applied to inactive email accounts on an Outlook/Exchange installation)

John,

I also use Outlook 2007 to receive email sent to multiple addresses (@yahoo, @gmail, etc.), and I was able to set up a rule that put incoming email into a folder based on the account (email addres) the item was received through.

(ed.) I'm not familiar with setting a rule at the Exchange server, but you could direct all inactive emails to a single machine (such as yours) and add to the rule below to "forward to specified person or distribution list" option to the rule below.

1. On the Toolbar, select Tools - > Rules and Alerts

2. Select "New Rule"

3. Click on the "Check messages when they arrive" under the Start a blank rule category.

4. Select the option "through the specified account". A dialog with a drop-down listing all the accounts set up in Outlook is presented.

5. Scan through the rest of the rules to see if you want additional rules.

6. Select Next and select "move it to the specified folder" (or move a copy) and specify the Outlook folder to move the email to when received. Optionally, select the option to also forward the email to a person or distribution list.

7. Add any other rules you wish, then press Next.

8. Add any exceptions, turn the rule on, give the rule a name, and you should be finished.

You can use Run Rules Now from the rules and alerts dialog to process your inbox using the new rule.

Much easier than trying to convince Outlook to run VBA scripts with all the security model restrictions.
PJ in (usually sunny) FL

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Emails being sent to an email alias

Post by StuartR »

PJ, that is the method that I use too. It works well if the emails are received through different accounts.

I have a number of separate accounts, but I also have a catchall email address which receives everything sent to *@mydomain.com, and these all end up being received by a single account. It would have been really useful to be able to apply rules based on the address the email was sent to but I never did find a way.
StuartR


JoeP
SilverLounger
Posts: 2048
Joined: 25 Jan 2010, 02:12

Re: Emails being sent to an email alias

Post by JoeP »

Try setting up a Hub Tansport rule in Exchange. The format is very similar to the Outlook.

Joe
Joe

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Emails being sent to an email alias

Post by John Gray »

Thanks, everyone!

Once I get half a day free at work I'll look into all this further. The Hub Transport idea sounds interesting because if it's all done on the Exchange Server, then I won't need any rules on the PCs... And maybe the To: alias address won't have been resolved to the primary email address at that stage - who knows?!
John Gray

Venison is quiet deer, and quite dear.