• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

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 the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

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 "Run-a-Script Rules Missing in Outlook"

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:

  • A simple run a rule script marks Outlook messages read when the messag
    Use a run a script rule to mark messages read
  • Use a Rule to delete older messages as new ones arrive
  • Convert RTF Messages to Plain Text Format
  • Send a New Message when a Message Arrives

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.

Subscribe
Notify of
18 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Chris Powers (@guest_208995)
October 14, 2017 10:56 am
#208995

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

0
0
Reply
auhcj (@guest_206124)
May 1, 2017 11:19 pm
#206124

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  auhcj
May 6, 2017 10:30 am
#206415

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

1
0
Reply
Mo8 (@guest_208323)
Reply to  auhcj
August 20, 2017 11:50 pm
#208323

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Mo8
August 21, 2017 1:04 pm
#208327

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

0
0
Reply
auhcj (@guest_206123)
May 1, 2017 10:43 pm
#206123

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?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  auhcj
May 2, 2017 1:48 pm
#206134

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.

0
0
Reply
auhcj (@guest_206055)
April 26, 2017 5:14 am
#206055

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  auhcj
May 6, 2017 10:42 am
#206416

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.

0
0
Reply
Penelope (@guest_192470)
August 11, 2015 12:04 pm
#192470

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

2
0
Reply
claudiu (@guest_191369)
June 18, 2015 3:59 am
#191369

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

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  claudiu
August 13, 2015 5:19 pm
#192555

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

0
0
Reply
Pete (@guest_188370)
January 2, 2015 9:22 am
#188370

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

5
0
Reply
Pete (@guest_188369)
January 2, 2015 9:16 am
#188369

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!

2
0
Reply

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

Latest EMO: Vol. 30 Issue 15

Subscribe to Exchange Messaging Outlook






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?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • Remove a password from an Outlook *.pst File
  • Reset the New Outlook Profile
  • Maximum number of Exchange accounts in an Outlook profile
  • Save Attachments to the Hard Drive
  • How to Hide or Delete Outlook's Default Folders
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
  • Use PowerShell to Delete Attachments
  • Remove RE:, FWD:, and Other Prefixes from Subject Line
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Newest Code Samples

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

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

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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

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

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment