Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get two kinds of e-mail: Discussion and Notifications. Notifications are auto-generated e-mails for things like code updates, issue tracking updates, and so forth. I have filters set up that give them a "Notification" category.

I want to keep the discussions indefinitely, since you never know when you might need the info from an e-mail six months ago. But, the notifications are ephemeral, and there is no need to have them clog disk space.

Is there a way to make Outlook auto-archive/auto-delete/purge/expire/whatever these e-mails based on the category?

share|improve this question
up vote 1 down vote accepted

Okay, I just wrote my first Outlook macro - so don't blame me if it deletes all your mails. Backup before you try! :)

In Outlook go to Tools > Macros > Macro. Enter the name you want to give the macro. I named mine "Delete_Old_Notifications".

Here's the macro code I wrote:

Sub Delete_Old_Notification()
    Dim ns As Outlook.NameSpace
    Set ns = Application.GetNamespace("MAPI")

    Dim inbox As Outlook.MAPIFolder
    Set inbox = ns.GetDefaultFolder(olFolderInbox)

    Dim item As Object 'Outlook.MailItem
    Dim Action As Integer
    Dim Categories, Category

    Action = 0

    For Each item In inbox.Items
    If Len(item.Categories & "") > 0 Then
        Categories = Split(item.Categories, ";")

        For Each Category In Categories
        Select Case LCase(Trim(Category))
            Case "notification":
            If DateDiff("d", item.ReceivedTime, Now) > 14 Then
                Action = 1
            End If
        End Select
    End If

    Select Case Action
        Case 1: MsgBox ("Delete '" & item.Subject & "'") 'item.Delete
    End Select

    Action = 0
End Sub

(Could be shorter, yes - but I built it to be extensible.)


  1. It looks in the standard inbox. If you want another folder, you have to modify the "Set inbox" folder. To look in subfolders of the inbox, add .Folders("foldername") at the end of the line
  2. Currently it checks if the mail has a category "notification". If you want another category, insert that in the Case. Just make it lower case because I convert them all to lower case - just to be sure.
  3. Currently it affects mails with an age of 14 days or above. See that in the If DateDiff line.
  4. Currently it does not actually delete, it just shows a notification. To make it actually work you need to remove the MsgBox near the bottom of the Sub and keep the line like this:

        Case 1: item.Delete

You might want to look at these two forum posts to find out...

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .