To Consider: Outlook Rules with Wildcards

Outlook doesn't like using Wildcards so much, but there's some tips: https://www.slipstick.com/outlook/rules/create-a-rule-with-wildcards/

Outlook doesn't support wildcards in rules, so you can't use use a * or ? character for wildcards. Instead, just specify the string you want to match. For example, if you want to match anything with "foo" in the subject text, then any the following would cause the rule to fire:

Foobar
Fools
tofoo

Note that the Rules Wizard supports wildcarding for e-mail addresses. By using the "with specific words in the recipient's address" and "with specific words in the sender's address" conditions, you can set rules for everyone from a particular domain, for example. See Creating Rules that Apply to an Entire Domain for more information.

However, these address rules do not work for Exchange Server recipients since the Exchange server addresses do not show up in the message header. To apply a rule to addresses within your Exchange organization (or exclude them), use @ as the word in the address (or exclude messages with @ in the address). See Creating a Rule to Filter Blank Senders for more information.

Display names

While a partial word filter won't work in all circumstances, you can use it to filter the display name of senders. For example, this rule will filter messages from Forum Administrator

rule test

Tip: Cancel the Check names dialog when adding the name to the people or group field:

Create a rule to filter partial display names

Run a Script rule

When a rule that looks for partial words isn't working, you can use a run a script rule. This example shows how to filter for the Sender's display name, but it can be used with any Outlook email field.

Sub CheckSpam(Item As Outlook.MailItem)
  If InStr(LCase(Item.SenderName), "pfizer") Then
    Item.Delete
  End If
End Sub

Using Wildcards in a Script

You can use wildcards in a script, either by using the method below or regex.

So on this topic... how about moving all messages that say
Invoice AI-SO-11786 from My Company
where the invoice number changes each time?

Assuming AI-SO- is in every invoice and only the numbers change, the next example shows one way to use wildcards in a script. It works with 5 or more digits (or characters) following ai-so-. If the letters are always upper case, you could get away with removing LCASE and using upper case letters in the macro.

The rule looks for the word invoice in the subject or body and if found, runs this macro to check the subject.

Sub MoveInvoices(Item As Outlook.MailItem)
Dim MoveFolder As Folder
Set MoveFolder = Session.GetDefaultFolder(olFolderInbox)
Set MoveFolder = MoveFolder.Folders("Move")
     If LCase(Item.Subject) Like LCase("*ai-so-?????*") = True Then
      Item.Move MoveFolder
  End If
End Sub

See Outlook's Rules and Alerts: Run a Script for more information on using a run a script rule.

This entry was posted in Technical. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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