Search code examples
vbaoutlook-2010

Outlook 2010 Rule: Move message if greater than 5 recipients


The only time I get emails with 5+ recipients is when the office gossip is going around. I would love to make a rule/filter to move any incoming message with more than 5 recipients into a junk folder.

Is that possible with Outlook 2010? I could not find anything like that in the default rules, wasn't sure if you could VBA the rule via Macro or something.

Any insight, help, or resources are appreciated.


Solution

  • I wrote the VBA script using the resources DeanOC provided if anyone is interested.

    This script takes all incoming emails and counts the recipients in the To: field,if recipient count is greater than 5, marks it as read, and moves is to a Gossip folder.

    There is also a secondary condition to check if subject contains CVS (we get updates from our concurrent version system which has 10 recipients) and move is to the appropriate folder.

    Sub moveOfficeGossip(item As Outlook.MailItem)
    
        Dim strNames As String, i As Integer, j As Integer, cvs As String
        Dim olApp As New Outlook.Application
        Dim olNameSpace As Outlook.NameSpace
        Dim olDestFolder As Outlook.MAPIFolder
    
        j = 1
        cvs = "CVS"
        strNames = item.To
        Set olNameSpace = olApp.GetNamespace("MAPI")
    
        For i = 1 To Len(strNames)
            If Mid(strNames, i, 1) = ";" Then j = j + 1
        Next i
    
        If (j >= 5) Then
            If InStr(UCase(item.subject), cvs) Then
                Set olDestFolder = olNameSpace.Folders("Personal Folders").Folders("Filtered").Folders("CVS")
                item.Move olDestFolder
            Else
                Set olDestFolder = olNameSpace.Folders("Personal Folders").Folders("Filtered").Folders("Gossip")
                item.UnRead = False
                item.Move olDestFolder
            End If
        End If
    
    End Sub
    

    I apologize if this is not in the most formal format and I know that it can be organized a bit better, but this was my first attempt at using any Visual Basic syntax.