Home » Exchange Server » Searching Message Tracking Logs by Sender or Recipient Email Address

Searching Message Tracking Logs by Sender or Recipient Email Address

Continuing my series of tips on searching message tracking logs using PowerShell, in this article I will demonstrate a few techniques for searching logs based on sender or recipient email address.

The Get-MessageTrackingLog cmdlet provides two parameters for specifying sender and recipient email addresses as search criteria.

  • -Sender – a single SMTP address for the sender of the email message
  • -Recipients – one or more SMTP addresses for the recipients of the email message

Both parameters are optional, so if they are omitted the search will return all senders, all recipients, or all of both.

To demonstrate the use of these parameters consider the following email message sent from Alan Reid to three recipients.

Searching Message Tracking Logs by Sender Email Address

Because I happen to have sent this test message within the last hour it is not very difficult for me to search for by combining the -Sender parameter with the -Start parameter to search within a time/date range.

However, if I were searching over a broader time range I may see more results than I really want to see.

So in the case where I want to search a broader time window, but see fewer irrelevant results, I can combine the -Sender and -Recipients parameters in my search command.

Searching Message Tracking Logs by Recipient Email Address

It doesn’t matter whether the recipient was in the To, CC, or BCC of the message, the search will return any match regardless. Here the “Payroll report for September” email shown above is found even though Alex Heyne was one of several recipients and was in the CC field.

You can specify multiple recipient SMTP addresses simply by separating them with a comma. When you do this the condition is an “or” not an “and”. In other words, any messages with any one of the recipients will be returned in the results, they do not need to be messages sent to all the recipients.

Here both the payroll email sent to Alex and David, as well as another email sent only to David, are returned in the same results.

Searching Message Tracking Logs for Wildcard Values or Partial Matches

Unfortunately wildcard searches are not allowed with the -Sender and -Recipient parameters.

For example, this will return no results.

However, you can use wildcards if you pipe the output of Get-MessageTrackingLog into Where-Object instead.

In this situation it is wise to limit the search to a specific date range for better performance. Or, if you do need to search the entire set of log files remember to use “-Resultsize Unlimited”.

You can see that the wildcard is used with the -like comparison operator, but another technique is to use the -match comparison operator which doesn’t require the wildcard character.

The same use of Where-Object with -like or -match also applies to the sender email address.

Summary

As you can see the -Sender and -Recipients parameters give us some flexibility when searching message tracking logs. However in some cases we need to use the more powerful capabilities of Where-Object for wildcard and partial string matching.

Paul is a Microsoft MVP for Office Servers and Services. He works as a consultant, writer, and trainer specializing in Office 365 and Exchange Server. Paul is a co-author of Office 365 for IT Pros and several other books, and is also a Pluralsight author.
Category: Exchange Server

83 comments

  1. Kobus says:

    I’m looking for a way to count the outgoing mails per user from “day-one” of our mailserver.

    $msgs = get-messagetrackinglog -Sender “username@domain.nl” -EventID “SEND” -Start “1-1-2000 0:00:00”
    $msgs | Group-Object -Property Sender | Select-Object name,count | sort >C:NumberOutgoingMailsUsername.txt

    The number of mails I get in the output file (156x) is much lower than the message in the users Send items (8488 mails). What am I overseeing? Is this affected by the retention policy?

  2. John says:

    I’m trying to export to CSV mails sent out from a specific email using commands below:

    get-messagetrackinglog -Sender “email@domain.com” -EventID “SEND” -Start “4/5/2014 8:00:00 AM” -End “4/5/2014 12:00:00 PM” | Where-Object {$_.recipients -like “*gmail.com”} | Export-csv C:export.csv

    However, in the Recipients field is showing only System.String[] . How can I make it show real recipients email address.

  3. Naga Krishna says:

    Hi Paul,

    Good Evening..!!

    I have situation where the user ( xyz@abc.com) was transitioned to extermal organisation ( xyz@efg.com) . However, He is still continuing to receive emails from our internal users.

    We do not have objects for him either on exchange or AD. Early, Assumptions are that a DL might be involved with a object for him.

    How do we track the emails from internal users to this invisible object in our environent. Thanks

  4. Vairamuthu says:

    In exchange 2007, we have created a transport rule, whatever emails coming to this mailbox , one copy deliver to respective mailbox and other copy deliver to sharepoint portal. Normal emails delivering fine, however using attachment emails are not delivered.

    Any advice or suggestion?

    Thanks

  5. Vairamuthu says:

    I did message tracking. Any attribute will says whether attachements delivered successfully or not ? User complains pdf attachments not receiving.

    • You need to be clearer in your problem statement. Is the problem that the emails with attachments aren’t being received by SharePoint, or by the mailbox? Or both? Or are the emails being delivered but without the attachments?

  6. Paul says:

    Hi Paul,

    We have a client requirement to find all messages from a specific sender that have not been replied to within 24 hours. basically our client wants to be sure the messages are being followed up.

    So one of my clients employees receives an email from person@contoso.com and my client wants to get a report showing that his employee replied to that email from person@contoso.com within 24 hours. if the employee didn’t reply, the owner wants a report showing all the emails that were not replied to in a timely fashion. he wants this for all his employees.

    is there any way to track by conversation in powershell? can i match replies to original emails from the tracking logs or perhaps there is another way? any help would be greatly appreciated!

    • I think your client should invest in a system, perhaps a job ticketing system, where customer correspondence is logged automatically and that has the reporting capabilities he desires.

  7. Mir says:

    Thanks Paul for all the informative posts.
    After having gone through these, I did try the same on my production Exchange 2010 server and found the output as below:

    [PS] C:Windowssystem32>Get-MessageTrackingLog -Start (Get-Date).AddHours(-50) -resultsize unlimited | Where-Object {$_
    .recipients -match “hotmail”}

    EventId Source Sender Recipients MessageSubject
    ——- —— —— ———- ————–
    DSN DSN postmaster@mydomain.com.sa {muntader_2008@hotmail.com} Undeliverable: Electrical powe…
    FAIL SMTP postmaster@mydomain.com.sa {muntader_2008@hotmail.com} Undeliverable: Electrical powe…
    DSN DSN postmaster@mydomain.com.sa {esther_jimmy60@hotmail.com} Undeliverable: Possible Spam :…
    FAIL SMTP postmaster@mydomain.com.sa {esther_jimmy60@hotmail.com} Undeliverable: Possible Spam :…
    DSN DSN postmaster@mydomain.com.sa {abuali1444@hotmail.com} Undeliverable: It’s Talkif ica…
    FAIL SMTP postmaster@mydomain.com.sa {abuali1444@hotmail.com} Undeliverable: It’s Talkif ica…
    DSN DSN postmaster@mydomain.com.sa {mr-al-break@hotmail.com} Undeliverable: ??? ????? ???? CV
    FAIL SMTP postmaster@mydomain.com.sa {mr-al-break@hotmail.com} Undeliverable: ??? ????? ???? CV

    What I don’t understand here is we don’t have any postmaster account enabled anywhere but still it seems to be sending out mails automatically ?
    What do the DSN , FAIL imply ?
    Apart from these, I found other user mailboxes sending out emails to other users on the domain as well as out to the internet, but the users claim they never sent any such messages!
    Something is really fishy, could you advise where to start looking for trouble ?
    After some research I found “MicrosoftExchangeRecipientReplyRecipient” is blank and also RecipientValidation is set to false. Would any of these help ?

  8. Nicolai says:

    hi Paul

    Can you help with this?

    1)
    I dont get any output from “CC” or “BCC” with “Recipients”. It do not show

    If i ex use this script, and i know there is a mail sendt from “hotmail.Com” to “Frank@myfirm.com” where i am “CC” It will not show the message. It shows only output “sendt to me”. if i change sender to “Frank@myfirm.com” it will show the message.

    What should i use instead ?

    Get-TransportServer |
    Get-MessageTrackingLog -Start (Get-Date).Addhours(-48)
    -End (Get-Date)

    -EventId send
    -Sender "ME@myfirm.com"

    | Select-Object Recipients,timestamp,eventid `
    | Where {($_.Recipients -match ‘@hotmail.com’)}

    2) how do i use wildcards “@myfirm.com” for “sender”

    Thanks!!

    Best Regards

    Nicolai

    • 1) Recipients will include CC and BCC recipients in the results.

      2) As I demonstrate in the article above you can’t use wildcards. I also demonstrated how to work around that.

  9. Sinchan says:

    Hi Paul,

    I want to create a report as to when person ‘X’ received an email and when did he replied to it. Using exchange message tracking I can track it manually for a single mail , but I want to track it for all emails that was sent and replied for a particular user . Kindly advise how to do it?

    Thanks!
    Sinchan

    • Irving says:

      I think you could use these cmdlet:
      Get-MessageTrackingLog -Sender example@contoso.com -ResultSize Unlimited

      or if you want a cvs file use this one:

      Get-MessageTrackingLog -Sender “example@contoso.com” -Start 1/1/2015 -End 1/1/2015 | Select-Object eventid,sender,timestamp,@{Name=”Recipients”;Expression={$_.recipients}},@{Name=”RecipientStatus”;Expression={$_.recipientstatus}},messagesubject | Export-csv C:example.csv

      You could replace sender by recipient and remember star PS as admin for cvs option.

  10. Ernesto Pangilinan says:

    Dear Paul,

    I just want to ask why when I’m running the PS command Get-MessageTrackingLog -Sender user@domain.com. All I get is email with subject like “Read: RE: Building Progress Report”. I’m not getting the other email which should be there. All results have the prefix “Read:” appended by the subject of the email. Any ideas?

  11. IS says:

    Greetings Paul!
    Excellent post 1st of all.

    I have a problem with the PS command.
    We are on EX 07, sending number of emails to our clients from the email database . Once a year we would send mass email to our clients and get 1200-1600 undelivered emails with 4.4.7 and exact error below

    Delivery has failed to these recipients or distribution lists:

    user@somedomain.com

    Microsoft Exchange has been trying to deliver this message without success and has stopped trying. Please try sending this message again, or provide the following diagnostic text to your system administrator.

    sender is in this example sender@mydomain.com
    and recipients is pulled from our database, so probably * (wild card)

    I would like to get report (csv file) that would contain ONLY email addresses from those emails that are undelivered so I can remove email addresses them from the database.

    I have tried
    get-messagetrackinglog -sender “sender@mydomain.com” -EventID “FAIL” -Start “10/12/2014 1:00:00 AM” -End “12/12/2014 11:59:00 PM” |ft Recipients

    but not having luck.

    any suggestion ?

    Appreciated!

  12. Dan Candido says:

    Hi Paul,

    When using Send As…can the recipient see the originator of the email (abc@abc.com) in any of the the properties of the email or would it just show the displayed “sent as” (def@abc.com) email address?

    Thanks and appreciate the site,

    Dan

  13. Leonard says:

    Hi Paul ,

    How do i get the IPv4 address of the sending computer from Message Tracking results in field clientip ? and the serverip field is ::1 ??!!!

    I see in field clientip only IPv6 , is any possibility to see the IPv4 in this field of report .

    br
    leo

  14. Saaj says:

    Can we make use of get-messagetrackinglog to find out whether an email has been read if read tracking is enabled globally in the organization?

  15. Viral Rathod says:

    Paul, how to send output of meesage tracking logs via e-mail as attachment.

    Do you suggest any script so that on daily basis i can receive message tracking report of my user.

    The attachment should be csv.

    • I don’t have a script to do exactly that. But any Get-MessageTrackingLog results can be exported to CSV using Export-CSV. And sending email (including attachments) using PowerShell is something there’s a lot of tutorials around for. So I’m sure you could write a script to handle that.

  16. Brian says:

    Every time I try these commands I get :

    Get-MessageTrace : Invalid Organization value. I’m sure I have all the rights I need, any thoughts?

  17. Steve says:

    Get this on SBS 2011, oh well – The term ‘Get-MessageTrackingLog’ is not recognized as the name of a cmdlet, function, script file, or operable program. 🙁

  18. Paul Sathya says:

    Is it possible to get information on Attachments when doing message Tracking from exchange

    Get-TransportServer | get-messagetrackinglog -EventID “RECEIVE” -Start “6/10/2015 2:30:00 PM” -End “6/10/2015 4:00:00 PM” -ResultSize Unlimited | Select EventId,Source,Sender,ServerHostName,{$_.recipients},MessageId,MessageSubject,ClientIp,TimeStamp | Export-Csv “D:Rep-Cas1Example.Csv”

    the above command works fine for me with the info… but is it i can also have a Attachment name and size listed.

  19. Paul Sathya says:

    Is it possible to get information on Attachments when doing message Tracking from exchange

    Get-TransportServer | get-messagetrackinglog -EventID “RECEIVE” -Start “6/10/2015 2:30:00 PM” -End “6/10/2015 4:00:00 PM” -ResultSize Unlimited | Select EventId,Source,Sender,ServerHostName,{$_.recipients},MessageId,MessageSubject,ClientIp,TimeStamp | Export-Csv “D:Rep-Cas1Example.Csv”

    the above command works fine for me with the info… but is it i can also have a Attachment name and size listed.

    (sorry my mail id was incorrect in there)

  20. RobertK says:

    Great article.

    how can use message tracking to see when message is being sent to secondary smtp address and not primary?

    • If you need more detail than what the message tracking log shows you can enable protocol logging on the send connector for your org and look at those logs to see the SMTP connection that occurs.

  21. Ally says:

    Hi Paul, Thanks for the article. I want to trace all external emails sent using our SMTP server. I have tried below where pipeline but it doesn’t work if I add another one using comma. It only works if I put one domain. Do you have alternative where I can filter the results in CSV not to show our 3 domains. The goal is only to search emails sent to external address. Thanks!

    Works fine -where {$_.Recipients -notlike “*@ourdomain1.com”}
    Does not work – where {$_.Recipients -notlike “*@ourdomain1.com”,”*@domain2″,”*domain3″}

    • Can’t compare against multiple values like that. You’d need to use something more like

      Where {$_.Recipients -notlike “*@ourdomain.com” -and $_.Recipients -notlike “*@domain2”}

      And so on.

      There’s probably even better way that would leverage the Get-AcceptedDomains cmdlet but the above should work even if it isn’t the most elegant way of doing it.

      • Mark says:

        Maybe something like this?

        $Date = Get-Date -UFormat “%m.%d.%Y 00:00:00”
        $Messages = Get-Mailboxserver | Get-Messagetrackinglog -start $Date -eventid send -resultsize unlimited

        foreach ($Domain in (Get-AcceptedDomain).Name){
        $Messages = $Messages | where {$_.Recipients -notlike “*$Domain”}
        }

        $Messages | Group-Object -Property Sender | Select-Object name,count | sort count -desc | select -first 50 | ft -auto

        (top 50 senders: internal to external )

  22. Me says:

    Hi Paul,

    Appreciate all the efforts you’re making.

    I have a question, when I want to export this command:

    Get-MessageTrackingLog -Start “2-29-2016 7:00:00” -End “2-29-2016 14:00:00” -Sender “foo@bar.com” | select-object Timestamp,EventId,MessageSubject,Sender,Recipients

    to a CSV file, the Subject of the messages shows up correctly, but when I pipe it to Out-GridView, instead of the proper Subject it says “Systeem Administrator” in the MessageSubject column.

    Any idea why it does that and how it can be fixed?

    Also I don’t know where it gets the Systeem from, that’s dutch for System.

    Exchange 2013 CU11,

  23. Carlos says:

    Hi Paul,

    Is there by chance a way to do a Get-MessageTrackingLog in order to search for specific mail attachments in Exchange? I have been assigned an important email forensics project. The idea is to get a csv report with senders and recipients for all mail with this particular attachment.

    Thank you!
    Carlos

    • Message tracking doesn’t record data about attachments. If you already know the message ID of the email, then yes you can do message tracking for it. If not, look to Exchange’s eDiscovery searches instead. If you need to go deeper, look at inspecting mailbox contents via Exchange Web Services.

  24. kim says:

    Hi Paul,

    how to trace message to have an output like this;

    Received: from domain.com (IP address) by domain.com
    (IP address) with Microsoft SMTP Server id 8.3.348.2; Wed, 23 Mar 2016
    11:28:57 -0400

    Received: from Domain.com ([IP address]) by
    Domain.com with ESMTP; 23 Mar 2016 15:28:57 +0000
    X-SBRS: 4.7

  25. Shiva says:

    Hi Paul,

    We have sent a survey link to all employees to participate and got the only few participant.
    Now Management is asking for the report to check how many of them read the email or simply deleted or its has been moved to spam folder directly.
    Could you please advise to generate the report for the above conditions (Conditions : how many of them read the email or simply deleted or its has been moved to spam folder directly.)
    I generated the report that mail has been delivered to all the mailbox.
    Kindly help me on this and much appreciated

  26. Ramez Lawendy says:

    Dear PAUL ,

    Please I need a command for Power shell to Trace a mail from a specific sender to a specific recipient .
    Can you help me

    Best Regards
    Ramez Lawendy

  27. RickF says:

    Hi Paul,
    I ‘ve been reading your articles for years now. Your many PowerShell articles/examples have taught me a great deal. I am very grateful!! This is my first question.
    .
    The “from” listed in an email’s header also lists the sender’s name.
    e.g.: “From: SenderName ” .
    Is there anyway to capture the “SenderName” from the transaction logs? “$_.recipients” just lists the SMTP address. These emails will all be from external senders…. if they were internal, I could do a look up in AD.
    .
    Thanks in advance for your time in reply.
    …Rick

    • RickF says:

      My example got editted when posted. the example email address got removed. The line should read:
      e.g.: “From: SenderName “

      • RickF says:

        ….hmmm. Guess the submission process removes email addresses. trying example again in different format:
        e.g.: “From: SenderName $SomeAddressATexternalDomain.com$
        .
        I replaced the greater and less than symbols which surround the SMTP address using $.

  28. shalendra singh says:

    Hi!
    Could you please let us know, Can we monitor bulk email forwarder user from outbound and inbound. If yes, then how?

    Regards,
    Shalendra

  29. Shaun says:

    hello

    I was wondering if anyone has experienced the following Scenario:

    1) Some users have received messages where the “subject” is the same as the user id (for example, “userid” is shaun and the message “subject” is shaun)

    2) Some users have received messages where the “subject” is part of the user id (for example, “userid” is myboylolipop and the message subject is myboylo)

    Is there anyway to query the message tracking logs to identify the mailboxes affected by numbers 1) and 2) above ?

    much obliged

  30. Moazzam Ali Quraishi says:

    Thank Mr. Paul for that script i am fan of yours and the scripts of yours are job saving 🙂 .

    Edit: Removed script. Please don’t post scripts and large code samples here in the comments, it breaks the layout of the page. Publish your scripts on your own blog, on GitHub, or in the TechNet Script Gallery.

  31. James says:

    I’m trying to track emails using the Get-MessageTrackingLog -MessageSubject “Leaver Form” -Recipients ….etc

    I need to outline the time it was sent to the time it was received, is there a better way to do this or what can I tack on to make this script give me time and dates?

  32. Dhananjay says:

    Hi Paul,

    I have ex2013, I’m looking for the way to get detailed information of sent email, for e.g details of system from which the message is sent. Is there any way I could do this?

    I have already tried get-logonstatistics, which I guess no more avaialble in ex2013.

    Regards,
    Dhananjay

  33. Rimvydas says:

    Hi,
    Is there any way to show all recipients completely? I have the situation when I tried to search recipients by matching for example @gmail.com. And when recipient is found and if there are a lot of recipients in matched email, recipients column is not show completely and ends with … Is it possible to show this column completely? I’ve tried out-string -Width but this didn’t help:(

  34. Raja M says:

    Hi Paul,

    how do we know whether there is an attachment or not in the email? i am not able to find through message tracking logs.

  35. vino says:

    Hi Paul,

    Iam looking for a script to count how many users read particular email.
    Like iam sending one email to internal distribution group. I want to check the email read count. I enabled read delivery report and able to see read report individually by clicking each user. Is there any way to export the report or any suggestions please.

  36. Hubby Brooks says:

    Our VP of IT is having an issue where all of her incoming email with subject of lunch goes straight to her deleted folder. No matter who sends. We have turned off all rules but still have the same results. She has windows 10 PC using Exchange email server.

Leave a Reply

Your email address will not be published. Required fields are marked *