Outlook 2010 rule: Move message if more than 5 recipients

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

Is this possible with Outlook 2010? I couldn't find anything like this in the default rules, wasn't sure if you could use a VBA rule through a macro or something.

Any insight, help or resources are appreciated.

+3


source to share


2 answers


I wrote a VBA script using DeanOC resources in case anyone is interested.

This script takes all incoming emails and counts the recipients in the box To:

, if there are more than 5 recipients, marks it as read and moves to the folder Gossip

.

There is also a secondary condition to check if the topic contains CVS

(we get updates from our parallel versioning system which has 10 recipients) and move 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 the most formal format and I know it can be organized a little better, but this was my first attempt at using any Visual Basic syntax.

+2


source


This link: How to replace text in the body of an incoming message with a hyperlink in Outlook 2010? shows how to create a custom action when using the "after message arrives" condition. You will need to modify the VBA code to poll your mail item to see if it has 5+ recipients, and then move the mail item to the junk mail folder.

Recipients can be found by looking at property MailItem.To

(semicolon delimited string)



If the message meets your criteria, you can use the method MailItem.Move

to move the message to the desired folder.

This link: Members of MailItem (Outlook) provide more information about the object MailItem

.

+3


source







All Articles