Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

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
0
ajj1
Asked:
ajj1
  • 2
1 Solution
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now