GFI Mailessentials – Macro's for Outlook using rcommands@mailessentials.com

I found some code the other week on Experts Exchange that has already helped me and will probably help other GFI Mailessentials Administrators with Bayesian analaysis learning of spam mails.   It was not quite complete code, and I changed the way it dealt with the mails a little, but you can change it back if you want.

With the below code, you can create two buttons in outlook for your users to press when they highlight an email that is either spam, or not spam.   This way, the Bayesian spam filters will learn directly from your user input.   The buttons can be added by simply right clicking on the menu, selecting customise, and creating a new menu that links to the macros…

The code simply forwards the mail, then deletes the message.    If you un-comment one line below you can also have the item move to deleted items instead of the sent items folder.

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
   
    Set objApp = CreateObject(“Outlook.Application”)
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case “Explorer”
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case “Inspector”
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
        Case Else
            ‘ anything else will result in an error, which is
            ‘ why we have the error handler above
    End Select
   
    Set objApp = Nothing
End Function

Sub ADDASSPAM()
    Dim myOlApp As New Outlook.Application
    Dim myItem, myForward As Object
  
    Set myItem = GetCurrentItem()
    Set myForward = myItem.Forward
   
    myForward.To = “
rcommands@mailessentials.com
    ‘The line below will place the sent item directly in Deleted Items
    ‘Set myForward.SaveSentMessageFolder = Application.GetNamespace(“MAPI”).GetDefaultFolder(olFolderDeletedItems)
       
    ‘The line below will add your text to the beginning of the message body.
    myForward.Body = “ADDASSPAM” & vbCrLf & myForward.Body
    ‘The line below sends the message.
    myForward.Send
   
    ‘The line below deletes the message you sent.
    Set myItem.SaveSentMessageFolder = Application.GetNamespace(“MAPI”).GetDefaultFolder(olFolderDeletedItems)
   
    myItem.Delete
       
    Set myForward = Nothing
    Set myItem = Nothing

End Sub

Sub ADDASGOODMAIL()
    Dim myOlApp As New Outlook.Application
    Dim myItem, myForward As Object
  
    Set myItem = GetCurrentItem()
    Set myForward = myItem.Forward
   
    myForward.To = “
rcommands@mailessentials.com
    ‘The line below will place the sent item directly in Deleted Items 
    ‘Set myForward.SaveSentMessageFolder = Application.GetNamespace(“MAPI”).GetDefaultFolder(olFolderDeletedItems)
       
    ‘The line below will add your text to the beginning of the message body.
    myForward.Body = “ADDASGOODMAIL” & vbCrLf & myForward.Body
    ‘The line below sends the message.
    myForward.Send
   
    ‘The line below deletes the message you sent.
    Set myItem.SaveSentMessageFolder = Application.GetNamespace(“MAPI”).GetDefaultFolder(olFolderDeletedItems)
   
    myItem.Delete
       
    Set myForward = Nothing
    Set myItem = Nothing
   
End Sub

Hope this helps someone!   Oh, and if you are a coder, I would love to know if you can implement any of the other commands available.   Maybe there is a market for someone to write a GFI Toolbar for Outlook?

EDIT:  Also, thanks to Garren Bellew whom added the command to delete the message after it got sent!

  6 Replies to “GFI Mailessentials – Macro's for Outlook using rcommands@mailessentials.com”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.