You can run this on a server with CDO installed (eg exchange server.)
You may wish to modify to only process the Inbox to generate the Inbox count...
'This script ..........
' USAGE: cscript ProcessNotesEmails.vbs SERVERNAME MAILBOXNAME
' This requires that CDO 1.21 is installed on the computer.
Dim rc, strDate, strLogFile
'Get date/time formatted as YYYYMMDD_HHMMSS
strDate= Year(Now) & Right(Month(Now)+100, 2) & Right(Day(Now)+100, 2) & "_" & Right(Hour(Now)+100, 2) & Right(Minute(Now)+100, 2) & Right(Second(Now)+100, 2)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' START OF USER CONFIGURABLE VARIABLES '''''''''''''''''''''''''''''''''''''''''''''
strLogFile="x:\somepath\somefile.log"
' END OF USER CONFIGURABLE VARIABLES '''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PrintLog "Starting script"
' Get command line arguments.
Dim obArgs
Dim cArgs
Set obArgs = WScript.Arguments
cArgs = obArgs.Count
Main
Sub Main()
Dim oSession
Dim oInfoStores
Dim oInfoStore
Dim oInfoStore2
Dim oRootFolder
Dim oFolders
Dim StorageUsed
Dim NumMessages
Dim strProfileInfo
Dim sMsg
' On Error Resume Next
If cArgs <> 2 Then
printlog( "Usage: cscript script.vbs SERVERNAME MAILBOXNAME")
printlog( " e.g. cscript script.vbs svr smitha")
Exit Sub
End If
'Create Session object.
Set oSession = CreateObject("MAPI.Session")
if Err.Number <> 0 Then
sMsg = "Error creating MAPI.Session."
sMsg = sMsg & "Make sure CDO 1.21 is installed. "
sMsg = sMsg & Err.Number & " " & Err.Description
printlog( sMsg)
Exit Sub
End If
strProfileInfo = obArgs.Item(0) & vbLf & obArgs.Item(1)
'Log on.
oSession.Logon , , False, True, , True, strProfileInfo
if Err.Number <> 0 Then
sMsg = "Error logging on: "
sMsg = sMsg & Err.Number & " " & Err.Description
printlog( sMsg)
printlog( "Server: " & obArgs.Item(0))
printlog( "Mailbox: " & obArgs.Item(1))
Set oSession = Nothing
Exit Sub
End If
'Grab the information stores.
Set oInfoStores = oSession.InfoStores
if Err.Number <> 0 Then
sMsg = "Error retrieving InfoStores Collection: "
sMsg = sMsg & Err.Number & " " & Err.Description
printlog( sMsg)
printlog( "Server: " & obArgs.Item(0))
printlog( "Mailbox: " & obArgs.Item(1))
Set oInfoStores = Nothing
Set oSession = Nothing
Exit Sub
End If
'Loop through information stores to find the user's mailbox.
For Each oInfoStore In oInfoStores
If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then
'&HE080003 = PR_MESSAGE_SIZE
StorageUsed = oInfoStore.Fields(&HE080003)
if Err.Number <> 0 Then
sMsg = "Error retrieving PR_MESSAGE_SIZE: "
sMsg = sMsg & Err.Number & " " & Err.Description
printlog( sMsg)
printlog( "Server: " & obArgs.Item(0))
printlog( "Mailbox: " & obArgs.Item(1))
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
Exit Sub
End If
'&H33020003 = PR_CONTENT_COUNT
NumMessages = oInfoStore.Fields(&H36020003)
if Err.Number <> 0 Then
sMsg = "Error Retrieving PR_CONTENT_COUNT: "
sMsg = sMsg & Err.Number & " " & Err.Description
printlog( sMsg)
printlog( "Server: " & obArgs.Item(0))
printlog( "Mailbox: " & obArgs.Item(1))
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
Exit Sub
End If
ProcessMailbox(oInfoStore)
sMsg = "Storage Used in " & oInfoStore.Name
sMsg = sMsg & " (bytes): " & StorageUsed
printlog( sMsg)
printlog( "Number of Messages: " & NumMessages)
End If
Next
' Log off.
oSession.Logoff
' Clean up memory.
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
End Sub
Sub ProcessMailbox(oIS)
printlog( "S1: " & oIS.Name)
printlog( "S2: " & oIS.RootFolder.Name)
For Each oF in oIS.RootFolder.Folders
'Process top-level folders
'Ignore non message folders?
'If Name in ("Journal, Contacts, etc") then continue.
If oF.Name = "Calendar" OR oF.Name = "Contacts" OR oF.Name = "Drafts" _
OR oF.Name = "Tasks" OR oF.Name = "Notes" OR oF.Name = "Outbox" _
OR oF.Name = "Journal" OR oF.Name = "Calendar Attachments" Then
printlog ("Skipping: " & oIS.Name & "/" & oF.Name)
Else
printlog( "Processing: " & oIS.Name & "/" & oF.Name)
ProcessFolder(oF)
End If
Next
End Sub
Sub ProcessFolder(StartFolder)
Dim objFolder
Dim objItem
Dim iCount
printlog( " " & StartFolder.Name)
' process all the subfolders of this folder
For Each objFolder In StartFolder.Folders
Call ProcessFolder(objFolder)
Next
' process all the items in this folder
'If StartFolder.Name = "Test" Then
iCount=0
For Each objItem In StartFolder.Messages
'printlog "Item: " & iCount
********* ADD UNREAD COUNT HERE:::::: If objItem.Unread = True Then unread_count=unread_count+1
Call ProcessItem(objItem)
iCount=iCount+1
Next
printlog "Items processed: " & iCount
'End If
Set objFolder = Nothing
End Sub
Sub ProcessItem(objItem)
On Error Resume Next
'Resolve all Recipient addresses in the item
objItem.Recipients.Resolve(False)
If Err.Number <> 0 Then
Printlog "Error on objItem.Recipients.Resolve # " & Err.Number & " " & Err.Description
End If
' Save item changes
objItem.Update
If Err.Number <> 0 Then
Printlog "Error on objItem.Update # " & Err.Number & " " & Err.Description
End If
On Error Goto 0
' Clear memory
Set objItem = Nothing
Exit Sub
End Sub
Sub printlog(strMessage)
'Open log file
'Append to log file
'
Dim oFSO, oFile
Dim strData
Dim strPattern, strReplace
Dim strD
Const ForAppending = 8
strD = FormatDateTime(Now(),0)
Set oFSO = CreateObject("Scripting.FileSystemObject")
If NOT oFSO.FileExists(strLogFile) Then
Set oFile=oFSO.CreateTextFile(strLogFile)
oFile.WriteLine strD & " - " & "Log file created."
oFile.Close
End If
Set oFile = oFSO.OpenTextFile(strLogFile, ForAppending)
oFile.WriteLine strD & " - " & strMessage
oFile.Close
Wscript.Echo strD & " - " & strMessage
End Sub