Friday, July 02, 2004

Tracking Email Delivery Time with WMI

One of the subjective problems in any email system is how long a message will take to reach its destination. Mail delivery times are never absolute and will always vary depending on a large number of variables out in the Big Wash (the Internet). Back in Exchange 5.5 one of the companies I used to work for used a software application that sent a mail via a poller and collector account and this is how they measured mail delivery times. In Exchange 2000 if you have message tracking logging enabled this information is actually keep on every message that is tracked in the Deliverytime property of the Exchange_MessageTrackingEntry WMI class. So if you have multiple servers at each point along the way you can look at the delivery time via WMI and you could actually work out how long this message is taking to be delivered over each hop.

So what i did today was write a script that looked at the two servers I've got in my production network and worked out firstly what was the delivery time of email from the point they hit my frount-end server and a 1024 event was logged in the message tracking logs to the point where they where delivered to the mailstore and a 1028 Event was logged on the mailbox server. Then you can work out the speed in bytes/second by divideing the size by the time taken. This didn't really present well as a text display so i think i'm going to need to put it in a database instead then maybe agregate the data to say 5 minute intervals and then graph it on a ASP page. You can also reverse the logic and look at outbound emails as well, this may be more interesting as you can then start graphing the delivery time to each different domain. Anyway here's the script (just reports on the last one hour of mailtraffic strcomputer in the frount-end strcomputer1 is the back-end)

strComputer = "frountend"
strComputer1 = "backend"
set shell = createobject("")
strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
minTimeOffset = shell.regread(strValueName)
toffset = datediff("h",DateAdd("n", minTimeOffset, now()),now())
dtListFrom = DateAdd("n", minTimeOffset, now())
dtListFrom = DateAdd("h",-1,dtListFrom)
strStartDateTime = year(dtListFrom)
if (Month(dtListFrom) < 10) then strStartDateTime = strStartDateTime & "0"
strStartDateTime = strStartDateTime & Month(dtListFrom)
if (Day(dtListFrom) < 10) then strStartDateTime = strStartDateTime & "0"
strStartDateTime = strStartDateTime & Day(dtListFrom)
if (Hour(dtListFrom) < 10) then strStartDateTime = strStartDateTime & "0"
strStartDateTime = strStartDateTime & Hour(dtListFrom)
if (Minute(dtListFrom) < 10) then strStartDateTime = strStartDateTime & "0"
strStartDateTime = strStartDateTime & Minute(dtListFrom)
if (Second(dtListFrom) < 10) then strStartDateTime = strStartDateTime & "0"
strStartDateTime = strStartDateTime & Second(dtListFrom) & ".000000+000"
Set objWMIService = Getobject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\MicrosoftExchangeV2")
Set objWMIService1 = Getobject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer1 & "\root\MicrosoftExchangeV2")
qstr = "Select * FROM Exchange_MessageTrackingEntry where entrytype = '1024' and OriginationTime > '" & strStartDateTime & "'"
Set colLoggedEvents = objWMIService.ExecQuery(qstr,,48)
For Each objEvent in colLoggedEvents
if instr(objEvent.Senderaddress,"") then

on error resume next
qstr1 = "Select * FROM Exchange_MessageTrackingEntry where entrytype = '1028' and TimeLogged > '" _
& strStartDateTime & "' and MessageID = '" & objEvent.MessageID & "'"
Set colLoggedEvents1 = objWMIService1.ExecQuery(qstr1,,48)
For Each objEvent1 in colLoggedEvents1
times = objEvent.Senderaddress & " " & objEvent.DeliveryTime & " " & objEvent1.DeliveryTime & " " _
& objEvent1.Size & " " & round(objEvent1.Size/objEvent1.DeliveryTime,0)
wscript.echo times
set colLoggedEvents1 = nothing
end if
wscript.echo "Done"


Anonymous said...

i use this blog alot to make a reporting easier in our domain, especially the tracking db.

but, i was not able to do the same thing with the "Tracking Email Delivery Time"

and i didn't find it somewhere here one the site , could you help me out Glen??

Anonymous said...

I am curious about your knowledge on "how email work". Your so-called "delivery time" is the delivery time of the email to 1st hop server, measure from your server. Relay server is commonly use in enterprise and your email could be dropped by by an reason (due to spam filter, black list, etc..).

Glen said...

Well actually what you will find in the Message Tracking logs are the transit times. Eg when then message passed though this mta. If you want to track message process and delivery times across MTA within a large exchange Org this is Okay. Its not a method to do end to end Transit time from a External host.


Anonymous said...


I am trying to report when one or more domains has received too much e-mail measured either by messages or bytes, but have some difficulty getting this thru WMI.

could you help me out Glen??