Outlook 2010 Rule: Move message if greater than 5 recipients

0

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 VB the rule. Any insight is appreciated.

kingkode

Posted 2013-02-06T21:09:28.553

Reputation: 101

With VBA it should be very much possible. Here's a macro that counts the number of recipients in a mail being sent (Application_ItemSend() event). You should be able to tweak it to run when a mail is received, using either the NewMailEx() or Items.ItemAdd() events as detailed here.

– Karan – 2013-02-08T03:35:05.470

Answers

0

I wrote the VBA script using resources from StackOverflow and SuperUser 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.

kingkode

Posted 2013-02-06T21:09:28.553

Reputation: 101