none
Macro to add sender's address to a rule based on sender RRS feed

  • Question

  • Hi,

    I am new to any outlook modification. I am looking for a way to quickly add sender's email address of an email in the inbox to a rule based on senders email address, so that next time an email comes from the same address, it automatically gets filed to a folder. Basically something like the "junk" button but for a normal folder.

    We need to run rules server-side since we all travel a lot so they need to process emails before they reach phones. I have done some very quick reading and it seems outlook doesn't allow for a VBA code to be written to do this for us and I have never worked with the COM addin.

    Is there a relatively simple way to do this? Perhaps to add a button to automatically add the email address of the currently selected email to the rule?

    Thank you,

    Tuesday, February 18, 2014 10:16 AM

Answers

  • Hello JDub80,

    >  it seems outlook doesn't allow for a VBA code to be written to do this for us

    You are on the wrong avenue. The Outlook object model provides all the required classes for getting the job done. There is no need to develop a COM add-in.

    Please take a look at the Managing Rules in the Outlook Object Model and How to: Create a Rule to Move Specific E-mails to a Folder articles in MSDN. For example, the latter provides the following code for creating a rule:

    Sub CreateRule() 
        Dim colRules As Outlook.Rules 
        Dim oRule As Outlook.Rule 
        Dim colRuleActions As Outlook.RuleActions 
        Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction 
        Dim oFromCondition As Outlook.ToOrFromRuleCondition 
        Dim oExceptSubject As Outlook.TextRuleCondition 
        Dim oInbox As Outlook.Folder 
        Dim oMoveTarget As Outlook.Folder 
     
        'Specify target folder for rule move action 
        Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox) 
        'Assume that target folder already exists 
        Set oMoveTarget = oInbox.Folders("Dan") 
         
        'Get Rules from Session.DefaultStore object 
        Set colRules = Application.Session.DefaultStore.GetRules() 
         
        'Create the rule by adding a Receive Rule to Rules collection 
        Set oRule = colRules.Create("Dan's rule", olRuleReceive) 
     
        'Specify the condition in a ToOrFromRuleCondition object 
        'Condition is if the message is from "Dan Wilson" 
        Set oFromCondition = oRule.Conditions.From 
        With oFromCondition 
            .Enabled = True 
            .Recipients.Add ("Dan Wilson") 
            .Recipients.ResolveAll 
        End With 
     
        'Specify the action in a MoveOrCopyRuleAction object 
        'Action is to move the message to the target folder 
        Set oMoveRuleAction = oRule.Actions.MoveToFolder 
        With oMoveRuleAction 
            .Enabled = True 
            .Folder = oMoveTarget 
        End With 
     
        'Specify the exception condition for the subject in a TextRuleCondition object 
        'Exception condition is if the subject contains "fun" or "chat" 
        Set oExceptSubject = _ 
            oRule.Exceptions.Subject 
        With oExceptSubject 
            .Enabled = True 
            .Text = Array("fun", "chat") 
        End With 
     
        'Update the server and display progress dialog 
        colRules.Save 
    End Sub 
    

    • Marked as answer by Marvin_Guo Wednesday, February 26, 2014 1:57 AM
    Tuesday, February 18, 2014 12:21 PM