UserPreferences

SpamOutlook


Note: This wiki is now frozen; you can no longer edit it, and no interactive features work.

1. Template for Help Pages

This is a bit of Outlook VBA code that when added to your Outlook Session will automatically categorize and move Spam recognized by SpamBayes to your Deleted Items folder and then permanently delete it. The only caveat is that you need to create a "Spam" folder. I have *never* run into a situation where SpamBayes classified a ham message as a spam message. Insert the following into your Outlook Session (note you may have to digitally sign your code with Office's Digital Certificate for VBA Projects tool and/or allow macros via the Tools/Macro/Security menu option).

1.1. Example

Private WithEvents olSpamItems As Items
Private WithEvents olSpammedItems As Items


Private Sub Application_Startup()
    Dim objNS As NameSpace
    Dim objInbox As MAPIFolder

    Set objNS = Application.GetNamespace("MAPI")
    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
    Set olSpamItems = objInbox.Folders("Spam").Items
    Set olSpammedItems = objNS.GetDefaultFolder(olFolderDeletedItems).Items
    
    Set objNS = Nothing
End Sub

Private Sub Application_Quit()
    ' disassociate global objects
    Set olSpamItems = Nothing
End Sub

Private Sub olSpamItems_ItemAdd(ByVal Item As Object)
Dim objNS As NameSpace
Dim objInbox As MAPIFolder
Dim objSpam As MAPIFolder
Dim objDeletedItemsFolder As MAPIFolder

If Item.Class = olMail Then
    Set objNS = Application.GetNamespace("MAPI")
    Set objSpam = objNS.GetDefaultFolder(olFolderInbox).Folders("Spam")
    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
    Set objDeletedItemsFolder = objNS.GetDefaultFolder(olFolderDeletedItems)
        If Not objDeletedItemsFolder Is Nothing Then
            Item.Categories = "Spam"
            Item.Move objDeletedItemsFolder
        End If
End If

    Set objDeletedItemsFolder = Nothing
    Set objSpam = Nothing
    Set objInbox = Nothing
    Set objNS = Nothing

End Sub


Private Sub olSpammedItems_ItemAdd(ByVal Item As Object)

If Item.Class = olMail Then
    If Item.Categories = "Spam" Then
        Item.Delete
    End If
End If
    
End Sub

Hope you find this helpful. Mason Phillips