WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Inspect mail messages - CDO

 Keywords: CDO Session Exchange 5.5 2000 2003 

Sample code from user

Our help-desk takes email problems and our manager needed to know how fast the desk was replying to our customers...

With this script you can then inspect the messages that have forward/replies and compare them to the received/sent dates and to a timediffsecs() to check response on emails.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       check reply/forward dates in messages...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;		  Fixes: (05/18/2006) the strProfileInfo parameter was fixed.
;
;       original script by Jay Alverson, 3/23/2001
;
;
;       this script uses winbatch and Collaborative Data Objects (CDO)
;       to search the MS Exchange 5.5 infostores for my email account.
;       in Outlook you can attach to one or more mailboxes (infostores)
;       when you use the application. this script searches for my personal
;       mailbox, then loops thru the top-level folders underneath. since
;       you can have subfolders & subfolders under them (ad nauseum) so
;       you'll have to code your own subsearches. nice thing is they're
;       all the same, you just need to allocate new objects/handles for
;       items. another good thing is that the .COUNT property seems to
;       work on these objects!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       in addition the script will check each mail message in the INBOX
;       a check each message for the dates a REPLY or FORWARD was done.
;       
;       since not all email messages have been replied to or forwarded
;       this information doesn't have pre-defined fields, so the information
;       is stored dynamically, with each REPLY or FORWARD date added onto the
;       message-fields end. try sending an email to yourself, do a reply and
;       then forward it to yourself, re-running the script each time.
;
;       script output goes to the clipboard.
;
;       THIS SCRIPT MAY NOT WORK IF YOU'VE RENAMED OR MOVED THE FOLDERS
;       in this example. my DELETED ITEMS folder is "above" my INBOX.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       you can alter this script to look thru PUBLIC FOLDERS, just
;       change the STRINDEXWILD statement to reflect this, then move
;       thru the subfolders, etc, etc.
;
;       also notice the end of the script:  cdoSession.logoff
;
;       I'm using winbatch 2000c and CDO.DLL (version 5.5.2448.0,
;       Collaboration Data Objects 1.21 for Windows NT) which you
;       can download from the Microsoft Web Site.
;
;       handy website...
;       http://msdn.microsoft.com/library/psdk/cdo/_olemsg_object_collections.htm
;       
;       setup the profile to logon to...
clipput("")


;The ProfileInfo parameter is used to create a temporary profile for the session. CDO generates a 
;random name for the profile. For an authenticated profile, the format of the string is
; @LF  where the server and mailbox names can be unresolved. Note 
;that the mailbox name is not the messaging users display name, but rather the alias or account
;name used internally by the users organization. For example, john should be used instead of John Doe. 
;
;For an anonymous profile, the format is  & vbLf & vbLf & "anon" where 
;the distinguished name of the server takes the form 
;/o=/ou=/cn=Configuration/cn=Servers/cn= 
;and any text between the vbLf characters is ignored. At least the /cn= entry is required; 
;if it is not specified in the ProfileInfo parameter, Logon returns CdoE_INVALID_PARAMETER. 

servername = "MyServer"   ;!!!!!!!!!!!!!! CHANGE TO FIT YOUR NEEDS !!!!!!!!!!!!!!!!!!!!!!
mailboxname = "MyMailbox" ;!!!!!!!!!!!!!! CHANGE TO FIT YOUR NEEDS !!!!!!!!!!!!!!!!!!!!!!
strProfileInfo = strcat(servername, @lf, mailboxname)

;       open the mapi session object and logon...
cdoSession = Objectopen("MAPI.Session")
cdoSession.Logon( , , @false, @false, , @True, strProfileInfo)
;       allocate the infostores object...
cdoInfoStores = cdoSession.InfoStores
;       init the display var...
infostoredata = ""
;       add the infostores count...
infostoredata = strcat(infostoredata, @crlf, "Number of Info Stores found:", cdoInfoStores.count)
;message("Info Stores", cdoInfoStores.count)
;       loop thru the infostores 1 by 1...
for is = 1 to cdoInfoStores.count
        item = cdoInfoStores.item(is)
;       message("Info Store #%is%", item.name)
;       look for my mailbox...
        if strindexwild(item.name, "Mailbox - Alverson Jay W", 1) > 0  ;!!!!!!!!!!!!!! CHANGE TO FIT YOUR NEEDS !!!!!!!!!!!!!!!!!!!!!!
        ;       we found it, now get a list of folders...
                dname = item.name       ; set display name...
                ;       add the mailbox name to the display data...
                infostoredata = strcat(infostoredata, @crlf, dname)
                ;       allocate an object for my mailbox...
                myMailbox = item
                ;       set the root folder object...
                myFolder = myMailbox.RootFolder
                ;       allocate the object for all folders...
                myFolderlist = myFolder.Folders
;               message("Folders for %dname%", myFolderlist.count)
;               add the folder count to the display data...
                infostoredata = strcat(infostoredata, @crlf, "Number Mailbox Folders found:",@tab, myFolderlist.count, @crlf)
                ;       loop thru the top-level folders one by one...
                for fld = 1 to myFolderlist.count
                        myFolderItem = myFolderlist.item(fld)
                        ;       look for only the INBOX or the DELETED ITEMS...
                        if strindexwild(myFolderItem.name, "Inbox", 1) > 0
        ;                       message("Folder Name", myFolderItem.name)
        ;                       add the folder name to the display data...
                                infostoredata = strcat(infostoredata, @crlf, "Folder found:", @tab,myFolderItem.name, @crlf, "Folder ID: ", myFolderItem.id)
                                ; allocate the messages in the folder to an object...
                                msgInFolder = myFolderItem.messages
                                ;       get a count in each folder...
                                infostoredata = strcat(infostoredata, @crlf, "Messages in Folder: ", msgInFolder.count)
;                               now look at each message, first allocate the object...
                                for ibi = 1 to msgInFolder.count
                                        msgitem = msgInFolder.item(ibi)
                                        msgfields = msgitem.fields
                                        mfcount = msgfields.count
                                        knowntimes = strcat(msgitem.timecreated, @tab, msgitem.timelastmodified, @tab, msgitem.timereceived, @tab, msgitem.timesent)
                                        clipappend(strcat("Msg # %ibi%", @crlf, "Subject:", msgitem.subject, @crlf, "Fields:", mfcount, @crlf))
;                                       clipappend(strcat("Time Created:", msgitem.timecreated, @crlf, "Time LastModified:", msgitem.timelastmodified, @crlf))
;                                       clipappend(strcat("Time Created:", msgitem.timecreated, @crlf, "Time Expired:", msgitem.timeexpired, @crlf, "Time LastModified:", msgitem.timelastmodified, @crlf))
;                                       clipappend(strcat("Time Received:", msgitem.timereceived, @crlf, "Time Sent:", msgitem.timesent, @crlf))
;                                       if ibi == 3 ;16
                                                for xyz = 1 to mfcount
                                                        mfs = msgfields.item(xyz)
;                                                       message("%xyz% of %mfcount%", mfs.value)
                                                        if strindexwild(mfs.value, ":", 1) > 0 && strlen(mfs.value) == 19  ;  look for the date fields only
;                                                       clipappend(strcat(ibi, @tab, msgitem.subject, @crlf, mfcount, @tab, xyz, mfs.value, @crlf))
                                                        if itemlocate(mfs.value, knowntimes, @tab) == 0  ;check to see if this date isn't already a known field
;                                                               clipappend(strcat("Msg # %ibi%", @crlf, "Field #:", xyz, @crlf, "Date:", mfs.value, @crlf))
; look at the value in the previous field,
; if prev.value == 102 then it was a REPLY and this is the date the message was replied to
; if prev.value == 104 then it was a FWD and this is the date the message was forwarded
                                                                prev = msgfields.item(xyz-1)
                                                                if prev.value == 102
                                                                clipappend(strcat("Field #:", xyz, @crlf, "Sent Date: ", msgitem.timesent, @crlf, "Reply Date:", mfs.value, @crlf, "Elapsed Time: ", timediffsecs(mfs.value, msgitem.timesent)/60, " minutes", @crlf ))
                                                                endif
                                                        endif
                                                        endif
                                                next
;                                       endif
;                                       if matt.count > 0 then infostoredata = strcat(infostoredata, @crlf, strupper(msgitem.subject), " has ", matt.count, " attachments")
                                        clipappend(strcat("==============================================", @crlf))
                                next ; message in folder...
                                endif ; inbox information check...
                next    ; folder in collection...
        endif
next    ; infostore...
;       logoff, cleanup and display the data...
cdoSession.logoff
objectclose(cdoSession)
message("CDO Info Stores", infostoredata)
exit



Article ID:   W14939
File Created: 2006:05:18:09:10:54
Last Updated: 2006:05:18:09:10:54