To let your Outlook auto delete the emails from a specific sender from specific days, you can read this article. Here we will show you the detailed steps to use VBA code to get it.
When it comes to auto deleting emails, you may firstly think of the “AutoArchive” feature. However, it cannot filter the specific senders when auto archiving emails. Therefore, for instance, if you would like to auto delete the emails from a specific sender after x days, you should use the other means, such as the following one.
Auto Delete the Emails from a Specific Sender after X Days
- At the very outset, start your Outlook application.
- Then, trigger Outlook VBA editor according to “How to Run VBA Code in Your Outlook“.
- Next, copy the following VBA code into “ThisOutlookSession” project.
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInboxItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
Call DeleteEmailsFromSpecificSenderAfterXDays
End Sub
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim objMail As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
'From the specific sender
If objMail.SenderEmailAddress = "bob_black@datanumen.com" Then
'Set expiry time - after 5 days
objMail.ExpiryTime = objMail.ReceivedTime + 4
objMail.Save
End If
End If
End Sub
Private Sub DeleteEmailsFromSpecificSenderAfterXDays()
Dim strFilter As String
Dim objExpiredItems As Outlook.Items
Dim objExpiredMail As Outlook.MailItem
strFilter = "[ExpiryTime] <= " & Chr(34) & Now & Chr(34)
'Get all expired items
Set objExpiredItems = objInboxItems.Restrict(strFilter)
For i = objExpiredItems.Count To 1 Step -1
If objExpiredItems(i).Class = olMail Then
Set objExpiredMail = objExpiredItems(i)
'Auto delete expired emails from the specific sender
If objExpiredMail.SenderEmailAddress = "bob_black@datanumen.com" Then
objExpiredMail.Delete
End If
End If
Next
End Sub
- After that, restart Outlook to activate this macro.
- Since then, every time when a new email from the specific sender arrives in Inbox, it will be assigned with a specific expiry time – the specific days after it is received.
- Then, every time you start Outlook, Outlook will auto check and delete the expired mails from the specific sender.
Restore Outlook Data after Corruption
Perhaps you have encountered a variety of errors and troubles in Outlook. Then, have you ever confronted Outlook corruption? For example, if you frequently exit Outlook improperly, your PST file tends to get damaged. Generally, in such a case, you can select to retrieve Outlook data from backups. Or you can either use inbox repair tool or a reliable external tool, such as DataNumen Outlook Repair.
Author Introduction:
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover sql and outlook repair software products. For more information visit www.datanumen.com


