Retrieving inbox oldest message RRS feed

  • Question


    I've got a project to generate an alert when a specific exchange 2003 mailbox has a message that is older than X minutes via MOM.   There is a process/people that are supposed to ensure that email is handled within Y amount of time, so we want to trigger some alerts when that threshold is breached. 


    What's the best way to find out how old the oldest message is for a given mailbox (or what all the message dates are) in a given mailbox? 




    Tuesday, May 15, 2007 8:36 PM

All replies

  • There are a few ways to go about this depending on what language you want to use eg do you want to do this from a .NET app etc . If you just want a vbs script you can invoke from MOM and you have CDO 1.2 avaible on the machine where the script is going to run then its pretty easy eg


    Code Snippet

    snServername = wscript.arguments(0)
    mbMailboxName = wscript.arguments(1)
    set csCDOSession = CreateObject("MAPI.Session")
    pfProfile = snServername & vbLf & mbMailboxName
    csCDOSession.Logon "","",False,True,0,True, pfProfile
    If csCDOSession.Inbox.Messages.Count <> 0 then
     Set msMessage = csCDOSession.Inbox.Messages.GetFirst
     wscript.echo "Oldest Mail " & DateDiff("n",msMessage.TimeReceived,Now()) & " minutes old"
     Set msMessage = csCDOSession.Inbox.Messages.GetLast
     wscript.echo "Newest Mail " & DateDiff("n",msMessage.TimeReceived,Now()) & " minutes old"
     wscript.echo "Mailbox Empty"
    End if


    Otherwise if you are using .NET then you might want to look at using WebDAV to do a search of the inbox see http://msdn2.microsoft.com/en-us/library/aa123571.aspx if you order your search by the

    Code Snippet


    property this will give you a list of all the emails within a folder sorted by date.





    Wednesday, May 16, 2007 12:58 AM
  • Thanks!  I was able to use that to get information from my mailbox... Is there a trick to get access to another mailbox?   I'm guessing I've got active directory or exchange rights to deal with, but figured someone has the answer handy while I continue my search.



    Wednesday, May 16, 2007 4:24 PM
  • Yes you will either need to delegate access via Outlook or Assign the account rights via the ADUC either via the mailbox rights tab or give it Send AS and Receive AS rights


    Thursday, May 17, 2007 12:02 AM