Wednesday, December 19, 2007

How to effectively turn off gmail spam filtering in Outlook 2007

1) Setup POP3 access to your gmail account.
2) Setup IMAP access to your gmail account.
3) Select Tools menu - Macro - Visual Basic Editor
4) Add the code below to the "ThisOutlookSession" module.
5) Save and restart Outlook.

The private methods register an event handler for your gmail spam folder and the event handler promptly moves the item to your gmail inbox so it can be downloaded using POP3.

The public method shows up as a macro and you want to run that every time you start Outlook so any messages that are already in your gmail spam folder get moved to your gmail inbox.

The folder name "youruserid@gmail.com" is the name of your IMAP folder and will be your gmail email address by default if you didn't change it when you setup the Outlook account.

There might be lines that are word wrapped in the code below, but they should be easy to see and fix once you paste the code in to the Visual Basic Editor.
Option Explicit

Private WithEvents GmailSpamFolderItems As Items

Private Sub Application_Startup()
Set GmailSpamFolderItems = Application.Session.Folders("youruserid@gmail.com").Folders("[Gmail]").Folders("Spam").Items
End Sub

Private Sub GmailSpamFolderItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Item.Move Application.Session.Folders("youruserid@gmail.com").Folders("Inbox")
Set Item = Nothing
End Sub

Public Sub MoveGmailSpamToInbox()
Dim GmailInboxFolder As Outlook.Folder
Dim Item As Outlook.MailItem

Set GmailInboxFolder = Application.Session.Folders("youruserid@gmail.com").Folders("Inbox")
For Each Item In Application.Session.Folders("youruserid@gmail.com").Folders("[Gmail]").Folders("Spam").Items
Item.Move GmailInboxFolder
Next Item
Set GmailInboxFolder = Nothing
End Sub