Automatically deleting emails by date

Is there anyway to get exchange 2k3 sp2 (ent) to go through everyones inbox and automatically delete emails older than 90 days?
I've hacked at scripts off the net and they just seem to loop or do nothing?

here's what I've got so far: (opens a file of exchange alias's and uses it to access the mbox via backofficestorage)



dim strGetName

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Const FOR_READING = 1

strNamesFile = "names.txt"

'Read user names for modification from text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strNamesFile) Then
  Set objTextStream = objFSO.OpenTextFile(strNamesFile, FOR_READING)
Else
  WScript.Echo "Input file " & strNamesFile & " not found."
  WScript.Quit
End If

Do Until objTextStream.AtEndOfStream
  strGetName = objTextStream.ReadLine

mailboxurl = "file://./backofficestorage/domain/MBX/" & strGetName & "/inbox"
set Rec = CreateObject("ADODB.Record")
set Rs = CreateObject("ADODB.Recordset")
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ExOLEDB.DataSource"
Rec.Open mailboxurl, ,3
SSql = "SELECT ""DAV:href"", ""DAV:contentclass"" FROM scope('shallow traversal of """ & mailboxurl & """') " 
SSql = SSql & " WHERE (""urn:schemas:httpmail:datereceived"" < CAST(""" & isodateit(now()-90) & """ as 'dateTime')) AND ""DAV:isfolder"" = false"
SSql = SSql & " AND ""DAV:contentclass"" = 'urn:content-classes:message'"
Rs.CursorLocation = 2 'adUseServer = 2, adUseClient = 3
rs.open SSql, rec.ActiveConnection, 3
while not rs.eof
rs.delete 1
rs.movenext
wend
rs.close

Loop

objTextStream.Close


function isodateit(datetocon)
strDateTime = year(datetocon) & "-"
if (Month(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime & Month(datetocon) & "-"
if (Day(datetocon) < 10) then strDateTime = strDateTime & "0"
strDateTime = strDateTime & Day(datetocon) & "T" & formatdatetime(datetocon,4) & ":00Z"
isodateit = strDateTime
end function


Or does anyone know of a better way to do this?

thanks

AJJ
LVL 2
ajj1Asked:
Who is Participating?
 
rakeshmiglaniCommented:
you can set a mailbox manager policy and configure it to run on the mailboxes homed on the exchange server
0
 
rakeshmiglaniCommented:
If you plan to use it then there are some good articles in Microsoft Kb about mailbox manager. Just search the KB for "mailbox manager"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.