Reports of incoming emails with timestamp
Hi!
I must create reports of a mailbox for a customer of ours. The mailbox contains mails from many different mailboxes with different TO adresses. The report I would like must contain the received date and the to adress for each mail, not just a count.
I've tried to use the SMTP log, Transport rules, Outlook rules but there is no nice solution with these examples. The best result yet is with crystal reports towards the exchange server (i must go via a lokal outlook account and I must also move the emails to a public folder). The result is ok, but not great and very time consuming to work with and not suitable for the business people(the reports will be created every day, and not by the IT department).
The result should look like this:
Mailbox: Ext.Supportticket
To Receved
Customer.A@support.com 2008-11-28 10:01
Customer.B@support.com 2008-11-27 09:15
Customer.B@support.com 2008-11-27 09:13
Customer.B@support.com 2008-11-27 08:47
Customer.C@support.com 2008-11-26 13:45
Etc.
Any ideas of applications, scripts, logfiles etc. that could be used for this?
Regards/Magnus
November 28th, 2008 5:48pm
Hi Magnus,
You need to get all these information from Message Tracking Log.
If you are using Exchange 2007 then it is easy to get information with Powershell command in your required format. Check below article for further detail.
Exchange 2007 Message Tracking (Part 2)
http://www.msexchange.org/tutorials/Exchange-2007-Message-Tracking-Part2.html
Get-MessageTrackingLog
http://technet.microsoft.com/en-us/library/aa997573.aspx
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2008 10:30am
Hi!
This works just fine, but how can I configure which columns that should be displayed when I use the Get-MessageTrackingLog command?
Iwould like to see the "Timestamp" value and the recipents in the same way as if I use the Message Tracking log tool.
Regards!/Magnus
December 1st, 2008 6:46pm
Hi Magnus,
Then you have to just format the output table with Format-Table / FT command.
Lets say you are running below Get-MessageTrackingLog command and you want to output in below format then just pipe the output with FT Recipients, TimeStamp, MessageSubject
Recipients, TimeStamp, MessageSubject
Get-MessageTrackingLog EventID RECEIVE MessageSubject hello Start 01/12/2006 00:00:00 End 28/12/2006 18:50:00 | FT Recipients, TimeStamp, MessageSubject
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2008 6:54pm
Hi, and thanks Amit!
This works lika a charm and I can gather the information i a txt file.
I have one more question for you, it's probably easy but google didn't help me yet :-)
Do you have any ideas regarding to schedule the command above in ex sceduled tasks?
My goal now is to create the file every night so a folder and let the sql server collect the information every morning.
A second question, is it possible to have the output of the command directly to a sql database?
Thanks again, this helped me a lot!
/Magnus
December 9th, 2008 5:21pm
Ahaa, I was sure that many people are looking for it so I just posted an article yesterday about scheduling PowerShell script for Exchange tasks to run automatically and which has an example to get the result on email as an attachment.
How To: Schedule PowerShell Script for an ExchangeTask
http://exchangeshare.wordpress.com/2008/12/08/how-to-schedule-powershell-script-for-an-exchange-task/
I have doubt on exporting the data directly into SQL database and you may need to check at SQL side to combine the functionality with powershell something like importing the txt file back to SQL database.
Free Windows Admin Tool Kit Click here and download it now
December 9th, 2008 5:31pm
:-) Nice timing with your article!
One more question, when i try to export to csv the Recipients field will show System.String[], do you know why?
I'm almost finished and will soon give you some peace! ;-)
Command:
Get-MessageTrackingLog -Start "2008-12-09" EventID Receive -Recipients "magnus.larsson@xxx.se" | Select Timestamp, Sender, Recipients | Export-CSV c:\MailStat.csv
Result:
#TYPE System.Management.Automation.PSCustomObjectTimestamp,Sender,Recipients"2008-12-09 00:15:04",noreply@xxxxx.se,System.String[]"2008-12-09 03:11:10",noreply@xxxxx.se,System.String[]"2008-12-09 06:49:10",baltzar@yyyyy.se,System.String[]"2008-12-09 07:59:38",Robert.Bergstrom@zzzzz.se,System.String[]
December 9th, 2008 6:28pm
Hello,
Again a known issue. This is because of 'Recipients' is a multi-valued property (may have multiple recipient addresses) so it doesnt export to CSV properly. You need to join all the values (multiple smtp recipient addresses) first and then export it to CSV.
I dont have access of my test environment right now to testthis but below is the command with which you can get desired output in CSV.
Get-MessageTrackingLog -Start "2008-12-09" EventID Receive -Recipients "magnus.larsson@xxx.se" | Select Timestamp, Sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}} | Export-CSV c:\MailStat.csv
Hope this helps...!!!
Free Windows Admin Tool Kit Click here and download it now
December 9th, 2008 7:07pm
Amit Tank wrote:
Again a known issue. This is because of 'Recipients' is a multi-valued property (may have multiple recipient addresses) so it doesnt export to CSV properly. You need to join all the values (multiple smtp recipient addresses) first and then export it to CSV.
I just posted an article about this too...
PowerShell: Export Multivalued Properties
http://exchangeshare.wordpress.com/2008/12/10/powershell-export-multivalued-properties/
December 10th, 2008 7:00pm