Blank subject / to / sender fields

  • Thread starter Thread starter Colin
  • Start date Start date
C

Colin

I have found the following code that runs as a macro to
delete all mail that has a blank subject, or to or sender
field (i.e. SPAM).

My problem is, that when the deletion routine activates
(ObjInboxItems_ItemAdd) I get an outlook popup telling me
that a program is attempting to access incoming mail do I
want to allow this access.

Do any of you know of a better way of doing this.
Obviously I cant use the Rules wizard to set up new rules
as it wont accept blank inputs.

The code follows

******************************************************
' Run this code to start your rule.

Sub StartRule()

Dim objNameSpace As Outlook.NameSpace

Dim objInboxFolder As Outlook.MAPIFolder



Set objNameSpace = Application.Session

Set objInboxFolder = objNameSpace.GetDefaultFolder
(olFolderInbox)

Set objInboxItems = objInboxFolder.Items



End Sub



' Run this code to stop your rule.

Sub StopRule()

Set objInboxItems = Nothing

End Sub

' This code is the actual rule.

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

If Item.Class = olMail Then

If Item.To = "" Or Item.SenderName = "" Or
Item.Subject = "" Then

Item.Categories = "Suspected Junk"

Item.Save

Item.Delete

End If

End If



End Sub
******************************************************
 
Back
Top