• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins
    • Video Tutorials
    • EMO Archives
    • Outlook Updates
    • Outlook Apps
    • Forums

Create a rule to delete mail after a number of days

Slipstick Systems

› Outlook › Rules, Filters & Views › Create a rule to delete mail after a number of days

Last reviewed on August 29, 2018     18 Comments

A security update disabled the Run a script option in Outlook 2013 and 2016's rules wizard. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

July 24, 2011 by Diane Poremsky 18 Comments

You can combine a Rules Wizard rule with the AutoArchive feature of Microsoft Outlook to automatically delete messages as they age. There are two ways you can do this:

  1. Create a rule that moves messages meeting certain criteria to a folder. Configure the folder's Archive setting to delete messages.
  2. Setting an expire date on messages as they arrive.

In either case, AutoArchive will delete the messages for you once they age.

If you need help configuring autoarchive settings, watch the tutorial: Configuring AutoArchive settings in Microsoft Outlook.

Note: If you use Microsoft Exchange Server 2010 with online mailbox archives, you won't be able to use autoarchive in Outlook 2007 and 2010.

Set an expiration date on the messages

Follow these steps to create a run a script rule to add an expire date and then configure AutoArchive to delete the messages.
An expired message is marked with a strikethrough font
When a message is expired it's displayed in the message list in a gray strikethrough font.

Check macro security settings. Macro security should be set to Low during testing. Once you verify the macro works, you can use SelfCert to sign the macro, at which point you will change the security setting to allow signed macros only.

In Outlook 2010 and 2013, click File, Options, Trust Center. Click the Trust Center Settings button then Macro Settings. Select the bottom option for Low security. In Outlook 2007, look on the Tools menu for Trust Center, then Macro Security. In older versions of Outlook, go to Tools, Macros, Macro Security.

  1. Press Alt+F11 to open the VBA Editor.
  2. Right click on Project1 and choose Insert > Module
  3. Add the macro below to the new module.
  4. Create a rule, selecting Run a Script as the action. If you set all of the conditions in the rule, you can delete the If...Then and End If lines.
  5. Create a filter for your view that hides expired messages between AutoArchive runs.
    Hide expired message filter
  6. Configure AutoArchive to delete expired messages.
    Delete expired messages using autoarchive

The macro will set the message to expire in 1 day. You can use .5 to expire the message after 12 hours.

If you use conditions in the rule to filter the messages, you can remove the If...Then and End If lines from the code.

Sub SetExpire(Item As Outlook.MailItem)

If Left(LCase(Item.Subject), 7) = "weather" Then
    Item.ExpiryTime = Now + 1
    Item.Save
End If

End Sub

If you use Outlook 2013 or Outlook 2016 and don't see the run a script option in rules, see

Move messages to a new folder

  1. Create a rule that moves messages to a folder.
  2. Switch to this folder, then right click on the folder and choose Properties.
  3. On the AutoArchive tab, choose how often to clean out items and whether they should be archived or deleted.
    Configure autoarchive setting by folder

More Information

More Run a Script Samples:

  • Autoaccept a Meeting Request using Rules
  • Automatically Add a Category to Accepted Meetings
  • Blocking Mail From New Top-Level Domains
  • Convert RTF Messages to Plain Text Format
  • Create a rule to delete mail after a number of days
  • Create a Task from an Email using a Rule
  • Create an Outlook Appointment from a Message
  • Create Appointment From Email Automatically
  • Delegates, Meeting Requests, and Rules
  • Delete attachments from messages
  • Forward meeting details to another address
  • How to Change the Font used for Outlook's RSS Feeds
  • How to Process Mail After Business Hours
  • Keep Canceled Meetings on Outlook's Calendar
  • Macro to Print Outlook email attachments as they arrive
  • Move messages CC'd to an address
  • Open All Hyperlinks in an Outlook Email Message
  • Outlook AutoReplies: One Script, Many Responses
  • Outlook's Rules and Alerts: Run a Script
  • Process messages received on a day of the week
  • Read Outlook Messages using Plain Text
  • Receive a Reminder When a Message Doesn't Arrive?
  • Run a script rule: Autoreply using a template
  • Run a script rule: Reply to a message
  • Run a Script Rule: Send a New Message when a Message Arrives
  • Run Rules Now using a Macro
  • Run-a-Script Rules Missing in Outlook
  • Save all incoming messages to the hard drive
  • Save and Rename Outlook Email Attachments
  • Save Attachments to the Hard Drive
  • Save Outlook Email as a PDF
  • Sort messages by Sender domain
  • Talking Reminders
  • To create a rule with wildcards
  • Use a Macro to Copy Data in an Email to Excel
  • Use a Rule to delete older messages as new ones arrive
  • Use a run a script rule to mark messages read
  • Use VBA to move messages with attachments

Create a rule to delete mail after a number of days was last modified: August 29th, 2018 by Diane Poremsky

Related Posts:

  • Use a Rule to delete older messages as new ones arrive
  • Run a Script Rule: Send a New Message when a Message Arrives
  • Outlook's Rules and Alerts: Run a Script
  • Use VBA to move messages with attachments

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

18
Leave a Reply

2500
Photo and Image Files
 
 
 
Audio and Video Files
 
 
 
Other File Types
 
 
 
2500
Photo and Image Files
 
 
 
Audio and Video Files
 
 
 
Other File Types
 
 
 

  Subscribe  
newest oldest most voted
Notify of
Chris Powers
Chris Powers

Sorry, but not quite following the steps.

I've completed the Trust Center step
I've added the macro (module?) in that you provided (SetExpire) and just changed the subject to something I'm interested in

But step 4, understand that this has changed and it needs to be another macro - tried to use your example and added another module but can't get it to run and so guessing my first macro (module?) isn't running either....

In step 5 - where does one create a filter? And since I (want) to run auto-archive daily and my macro flags them > 1 day, not sure I need this step, but am curious.

Step 6 - this is for turning it on globally, correct? Just "nervous" that there may be other emails that are set to expire that I didn't set - or my macro is wonky and I just flagged ever email to expire.

Sorry for all the questions, if you have a example for this topic but at a lower level or with video, can you point me to it?

Thanks a ton in advance, this would be a huge help for both my wife and I.
Chris

Vote Up00Vote Down Reply
October 14, 2017 10:56 am
auhcj
auhcj

Also, when I tried running the script, Excel VBA prompted me for a Macro name.

I am wanting to set different expiry dates (2-7days) for each sender.

Vote Up00Vote Down Reply
May 1, 2017 11:19 pm
Diane Poremsky
Diane Poremsky

It's an Outlook macro (not Excel) and run a scripts can only be run by the script - you can use a stub macro to test the script on a selected message.
Sub TestRunScript()
Dim objApp As Outlook.Application
Dim objItem As MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
SetExpire objItem

End Sub

Vote Up10Vote Down Reply
May 6, 2017 10:30 am
Mo8
Mo8

Hi Diane, i'm sorry but i couldnt see how to start a new question ???
Thank you for all your help, i have used Slipstick many times but never asked a question.

My question is about steps 4 and 5 above ( I have done 1 -3), where do i "create a rule" and " create a filter, i can't see anywhere in VBA editor and in Create Rule in Outlook (2013) there is no option to Run a Script.

Also , fyi, when i went into Trust Center (2013) there was no "Macro Security" but there was Macro Settings which had options to change security levels.

Thank you for you help.

Vote Up00Vote Down Reply
August 20, 2017 11:50 pm
Diane Poremsky
Diane Poremsky

See https://www.slipstick.com/outlook/rules/outlook-2016-run-a-script-rules/ - a recent update removed run a script rules for security reasons.

Vote Up00Vote Down Reply
August 21, 2017 1:04 pm
auhcj
auhcj

Hi Diane,

In Hotmail, there is the sweep rule to quickly delete unwanted emails in the Inbox with options to automatically delete all incoming email,
to keep only the latest email, or to delete email older than 10 days—all from a particular sender.

Am I able to create the same rules in MS Outlook?

Vote Up00Vote Down Reply
May 1, 2017 10:43 pm
Diane Poremsky
Diane Poremsky

No, outlook doesn't support Sweep. However, the rule in outlook.com should run before outlook downloads the mail.

If you need this on accounts other than outlook.com, you'll need to use a script in outlook.

Vote Up00Vote Down Reply
May 2, 2017 1:48 pm
auhcj
auhcj

Hi Diana,

I updated the script to expire in 2 days instead of 1.

So when creating the filter to hide the emails, what values should I enter for the expired field?

Also when I created the filter for the emails, I entered the "From" email however all my emails in that folder were hidden. I only want the emails from that sender and expiry to be hidden.

Vote Up00Vote Down Reply
April 26, 2017 5:14 am
Diane Poremsky
Diane Poremsky

I would use 'on or after' and the word tomorrow then add a second rule for expires - choose does not exist. This will show everything with either no date set or a future date set.

When you use the same field in the a filter, they are OR'd - different fields use AND operator.

Vote Up00Vote Down Reply
May 6, 2017 10:42 am
Penelope
Penelope

Yes MS, PLEASE add a time expiration rule option. A time expiration rule is about as basic (pardon the pun) as expired milk.

Vote Up20Vote Down Reply
August 11, 2015 12:04 pm
claudiu
claudiu

I also got an issue, using outlook 2013, created 2 rules, one to move messages from inbox to local inbox (pst) and copy messages from send items to local send items - because i can't configure a move rule for that folder.
i have deactivated autoarchive general settings from file-options-advanced-autoarchive and only configured autoarchive on the send items folder with following options: clean out items older then 1 day and permanently delete old items.
unfortunately any emails older then 1 day don't get deleted as they are supposed to.
can't seem to find where i did wrong.

thank you

Vote Up00Vote Down Reply
June 18, 2015 3:59 am
Diane Poremsky
Diane Poremsky

You'll need autoarchive settings enabled and change the settings on the folders you don't want archived.

Vote Up00Vote Down Reply
August 13, 2015 5:19 pm
Pete
Pete

Come on MS, add the feature to set the expire time directly by rules!!!! Its only about 10 years since that was first requested!!!

Vote Up40Vote Down Reply
January 2, 2015 9:22 am
Pete
Pete

Thanks - this helped point me in the right direction. Although I prefer to use the received time instead of 'now'. Then it works for 'Run Now' Rules as well:

Sub SetExpire(Item As Outlook.MailItem)

Item.ExpiryTime = Item.ReceivedTime + 1
Item.Save

End Sub

Also - if you are using rules to select the correct messages you DO NOT need to add conditions to the VBA. Just be careful that the rules work first!

Vote Up20Vote Down Reply
January 2, 2015 9:16 am

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 24 Issue 3

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

  • Popular
  • Latest
  • Week Month All
  • Adjusting Outlook's Zoom Setting in Email
  • The Signature or Stationery and Fonts button doesn't work
  • Security Certificate Warning in Microsoft Outlook
  • This operation has been cancelled due to restrictions
  • How to Remove the Primary Account from Outlook
  • Two Copies of Sent Messages in Outlook
  • Outlook's Rules and Alerts: Run a Script
  • iCloud error: Outlook isn't configured to have a default profile
  • Outlook is Not Recognized as the Default Email Client
  • To Cc or Bcc a Meeting Request
  • Outlook.com: Manage Subscriptions
  • Group By Views don’t work in To-Do List
  • Category shortcuts don’t work
  • How to disable the Group By view in Outlook
  • Adjusting Outlook's Zoom Setting in Email
  • Change the Subject of an Incoming Message
  • Creating Signatures in Outlook
  • Scheduling a Recurring Message
  • OneNote is missing from Office 365 / 2019
  • Create Rules using PowerShell
Ajax spinner

Newest VBA Samples

Adjusting Outlook's Zoom Setting in Email

Move email items based on a list of email addresses

Remove prefix from Gmail meeting invitations

How to hide LinkedIn, Facebook, Google and other extra contact folders in Outlook.com

Use VBA to create a Mail Merge from Excel

Open multiple Outlook windows when Outlook starts

Set most frequently used Appointment Time Zones

How to change the From field on incoming messages

VBA: File messages by client code

Update Contact Area Codes

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Better Outlook Reminders?
  • Coming Soon to Windows 10: Office 365 Search
  • Outlook Links Won’t Open In Windows 10
  • BCM Errors after Upgrading to Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook 2016 Top Issues

  • The Windows Store Outlook App
  • Emails are not shown in the People Pane (Fixed)
  • Calendars aren’t printing in color
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • BCM Errors after October 2017 Outlook Update
  • Excel Files Won’t Display in Reading Pane
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

OutlookCode.com

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes
  • “Live” Group Calendar Tools

Convert to / from Outlook

  • Converting Messages and Calendar or
    Address books
  • Moving Outlook to a New Computer
  • Moving Outlook 2010 to a new Windows computer
  • Moving from Outlook Express to Outlook

Recover Deleted Items

  • Recover deleted messages from .pst files
  • Are Deleted Items gone forever in Outlook?

Outlook 2013 Absolute Beginner's Guide

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Sync & Share

Share Calendar & Contacts

Synchronize two machines

Sharing Calendar and Contacts over the Internet

More Tools and Utilities for Sharing Outlook Data

Access Folders in Other Users Mailboxes

View Shared Subfolders in an Exchange Mailbox

"Live" Group Calendar Tools

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Outlook BCM | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2019 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

You are going to send email to

Move Comment