Home > Blockchain >  How can I set messageheader when creating a new rule
How can I set messageheader when creating a new rule

Time:04-27

I am using vba code to create a rule from text in an input file. One of the rule conditions I need in a rule is to examine the message header of a received email and move the email to a specific folder based on the message header content. I have tried using the .TEXT property to no avail. I have Googled questions to find a solution but nothing comes up. I am using the vba code to create over 300 rules, many of which require the message header test. Any help would be greatly appreciated Ron EDIT: I am getting the same error when I am assigning a text string to oRule.Conditions.Subject.Text in this code. EDIT: I just realised I didn't mention error - it's "Run time error '13' - Type mismatch" I have tried using String and Variant for the fields, I get the same message.

My code is as follows :

Dim strMessageHeader As Variant

    Do While Not EOF(1)
        Input #1, StrRuleName, strCond, strFrom, strSubject, strSentTo, strMessageHeader, strSendersAddress, strMoveTo, strSetCategory
' Create the rule
        Set oRule = colRules.Create(StrRuleName, olRuleReceive)
        
' What is the condition?
        Select Case strCond
        Case olConditionFrom            ' 1 - Condition is "from"
            Set oFromCondition = oRule.Conditions.From
            With oFromCondition
                .Enabled = True
                .Recipients.Add (strFrom)
                .Recipients.ResolveAll
            End With
        Case olConditionSubject         ' 2 - Condition is text "in the subject"
            Set oSubjectCondition = oRule.Conditions.Subject
            With oSubjectCondition
                .Enabled = True
                .Text = strSubject
            End With
        Case olConditionSentTo          ' 12 - Condition is "sent to a specific email"
            Set oSentToCond = oRule.Conditions.SentTo
            With oSentToCond
                .Enabled = True
                .Recipients.Add (strSentTo)
            End With
        Case olConditionMessageHeader   ' 15 - Condition is text "in the message header"
            Set oMsgHdrCond = oRule.Conditions.MessageHeader
            With oMsgHdrCond
                
                .Text = strMessageHeader
            End With

CodePudding user response:

You need to set Rule.Conditions.MessageHeader.Text property.

CodePudding user response:

I worked it out - the .text needs to be assigned using a text array not a text string or variant. I used the following that worked:

        Case olConditionMessageHeader   ' 15 - Condition is text "in the message header"
            Set oMsgHdrCond = oRule.Conditions.MessageHeader
            With oMsgHdrCond
                .Enabled = True
                .Text = Array(strMessageHeader)
            End With)
  • Related