Dim WithEvents olkInbox As Outlook.Items
Private Sub Application_Quit()
Set olkInbox = Nothing
End Sub
Private Sub Application_Startup()
Set olkInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub olkInbox_ItemAdd(ByVal Item As Object)
If Item.Class = olMail Then
SpamChecker Item
End If
End Sub
Sub SpamChecker(Item As Outlook.MailItem)
'On the next line edit the list of keywords as desired. Be sure to separate each word with a | character.'
Const KEYWORDS = "viagra|cialis|prescription|pharmacy|phizer"
Dim objRegEx As Object, colMatches As Object, bolSpam As Boolean
Set objRegEx = CreateObject("VBscript.RegExp")
With objRegEx
.IgnoreCase = True
.Pattern = KEYWORDS
.Global = True
End With
Set colMatches = objRegEx.Execute(Item.Subject)
If colMatches > 0 Then bolSpam = True
Set colMatches = objRegEx.Execute(Item.Body)
If colMatches.Count > 0 Then bolSpam = True
If bolSpam Then Item.Delete
Set colMatches = Nothing
Set objRegEx = Nothing
End Sub
|