MailBox Rule Deletes

5 pts.
Tags:
Microsoft Outlook
Microsoft Outlook rules
How do I sent up a mailbox rule that will automatically delete mail if older then one month

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello,
you can create a VBA script that handles this.
In Outlook press ALT+F11 and write your code as in the following example:

<pre>
Sub CustomMailMessageRule(Item As Outlook.MailItem)
‘ Must always be named as follows otherwise
‘ you cannot use it as an Outlook rule
DeleteOlder
End Sub

Sub DeleteOlder()
On Error GoTo DeleteOlder_err
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim SentDate As Date

Set ns = GetNamespace(“MAPI”)
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
For Each Item In Inbox.Items
‘ Work with the date difference of the “Item.SentOn” data and you have what you need
If DateDiff(“d”,Item.SentOn,Now) > 30 Then
….
End if
Next Item
DeleteOlder_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
DeleteOlder:
Resume DeleteOlder_exit
End Sub
</pre>

Once you’ve tested this you can simply create an Outlook rule that will be run according to your needs, I hope this helps.
Regards,
Alessandro

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following