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”

  1. August 28, 2006 at 1:48 pm

    Quote: (I deleted your post by mistake James)

    This was a great addition for my GFI administration but I just have two questions. Is there any way that I can stop the prompting of this application sending on behalf of myself?

    I tend to have my end users place all of the items in one general folder so that they can be added to GFI for analysis. Is there a way that once the first item is added, the application would automatically move to the next item and process it?

    Any advice would be appreciated.

    Thanks!

    James Reichner

  2. August 28, 2006 at 1:52 pm

    James,

    I am sure that it is possible. But you need a VB coder 🙂 I am not that man.

    Hopefully one of the other MVP’s on this server will be able to assist. Let me know if you don’t get anywhere with them and I will post to the bloggroup.

  3. James Nairn
    July 24, 2007 at 3:58 pm

    GFI’s Public Folder scanning will take care of users placing emails in one place and having GFI automatically process them.

    James Nairn
    Ignition Support Center

  4. July 27, 2007 at 6:42 am

    Hi James…

    Yes, it will…. but users dont want to drag emails in my experience. They want a click button 🙂

  5. Alex C
    October 31, 2007 at 9:53 am

    I agree, it would be a very useful to have a GFI toolbar with these sorts of actions as standard buttons.

    I’m currently trying to figure out how to get VBScripts to move and copy an email received in any
    user’s Outlook Inbox to the relevant GFI folder in the Public Folders. I would then create Macros for these and create new custom buttons to add to a new toolbar in Outlook.

    It needs to be as follows:
    Mailbox – Bob Jones>Inbox **–move to–>** Public Folders>Public Folders>GFI Antispam Folders>This is spam email

    In my experience – and maybe others agree – you want to *move* spam email and *copy* legitmate mail to their respective folders (as you don’t want to lose legitmate mail). I therefore think it would be useful to have ‘Move to This is spam email’ and ‘Move to Add to blacklist’, and ‘Copy to This is legitimate email’ and ‘Copy to Add to whitelist’.

    Any thoughts, or even VBScripts?

  6. December 15, 2008 at 1:07 pm

    This macro will move the highlighted email to the GFI This is spam public folder. Found it on a forum someplace and works perfectly.

    Sub MoveToSPAMFolder()
    Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
    Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem

    Set objNS = Application.GetNamespace(“MAPI”)

    For intX = 1 To objNS.Folders.Count
    If objNS.Folders.Item(intX).Name = “Public Folders” Then
    Set objFolder = objNS.Folders.Item(intX).Folders(“All Public Folders”)
    Set objFolder = objFolder.Folders(“GFI AntiSpam Folders”)
    Set objFolder = objFolder.Folders(“This is spam email”)
    Exit For
    End If
    Next

    If objFolder Is Nothing Then
    MsgBox “This folder doesn’t exist!”, vbOKOnly + vbExclamation, “Unable to find the GFI AntiSpam Folder”
    End If

    If Application.ActiveExplorer.Selection.Count = 0 Then
    ‘An email must be highlighted, otherwise exit
    Exit Sub
    End If

    For intX = ActiveExplorer.Selection.Count To 1 Step -1
    Set objX = ActiveExplorer.Selection.Item(intX)
    If objX.Class = olMail Then
    Set objEmail = objX
    objEmail.Move objFolder
    End If
    Next

    Set objFolder = Nothing
    Set objNS = Nothing
    End Sub

Leave a Reply

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