Link to home
Start Free TrialLog in
Avatar of elwaha
elwaha

asked on

Exchange 2007 Delete items in inbox 'x' days old

I need to be able to delete Items in my inbox that are 'x' days old.  

Running Exchange 2007, outlook client 2007 and Archives (PST's) are turned off to the users.  
ASKER CERTIFIED SOLUTION
Avatar of aissim
aissim
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elwaha
elwaha

ASKER

Article good, reading now..

To answer your first Q - Only on the users inbox, at the client.  
Good deal - just so you know, you CAN apply your policy to just the Inbox....it doesn't have to apply to all the managed folders.
Avatar of elwaha

ASKER

Aissim,
Can you at the client setup something like that for the single user out there?
Or do you know of any scripts that a user can have that would accomplish deletion older than 30 days?
Easiest way would be to right-click on the Inbox -> Properties. Switch to the AutoArchive tab and tick the 3rd radio button that reads "Archive this folder using these settings"

Set it to clean out items older than 1 Month (or 30 days, or whatever) - and 'permanently delete old items'.

Avatar of elwaha

ASKER

No AutoArchive tab,  The ability to create PST's has been disabled for all users.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elwaha

ASKER

I've found this...

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items
Set colFilteredItems = colItems.Restrict("[UnRead] = false")

For i = colFilteredItems.Count to 1 Step - 1
    If DateDiff("m", colFilteredItems(i).ReceivedTime, Now) > 1 Then
        colFilteredItems(i).Delete
    End If
Next

How can I set it to do the entire mailbox?  Or other folders under my inbox?
Check this out; it should hit all the sub-folders of the Inbox as well:

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objInbox = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objInbox.Items
Set colFilteredItems = colItems.Restrict("[UnRead] = False")

For i = colFilteredItems.Count to 1 Step - 1
    If DateDiff("m", colFilteredItems(i).ReceivedTime, Now) > 1 Then
        colFilteredItems(i).Delete
    End If
Next

GetSubfolders(objInbox)

Sub GetSubfolders(objParentFolder)
    Set colFolders = objParentFolder.Folders
    For Each objFolder in colFolders
      Set objSubfolder = objParentFolder.Folders(objFolder.Name)
      Set colItems = objfolder.items
      Set ColFilteredItems = colItems.Restrict("[UnRead] = False")
      
      For i = colFilteredItems.Count to 1 Step - 1
            If DateDiff("m", colFilteredItems(i).ReceivedTime, Now) > 1 Then
                    colFilteredItems(i).Delete
            End If
      Next

      GetSubfolders objsubfolder
    Next
end sub