Automatically deleting emails by date

Posted on 2006-05-23
Last Modified: 2008-02-01
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


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)
  WScript.Echo "Input file " & strNamesFile & " not found."
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 SSql, rec.ActiveConnection, 3
while not rs.eof
rs.delete 1



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?


Question by:ajj1
    LVL 35

    Accepted Solution

    you can set a mailbox manager policy and configure it to run on the mailboxes homed on the exchange server
    LVL 35

    Expert Comment

    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"

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
    Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
    In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
    This video discusses moving either the default database or any database to a new volume.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now