根据发件人地址中的单词指定Outlook规则条件

时间:2013-07-12 02:29:07

标签: c# outlook outlook-addin outlook-2010

根据the documentation,我应该能够在我的Outlook规则中指定一个条件,该条件基于发件人地址的部分字符串匹配进行匹配,方法是在TextRuleCondition.Text条件下指定要匹配的文本类型为olConditionSenderAddress

screenshot from msdn

但是,我找不到在Rule.Conditions对象中设置的适当属性。如果我枚举新创建的规则的条件,则不存在TextRuleCondition类型ConditionType == olConditionSenderAddress的现有条件。正确ConditionType的唯一条件是AddressRuleCondition,其中没有Text属性。

如何以编程方式在Outlook 2010规则中指定发件人地址包含特定字符串的条件?

1 个答案:

答案 0 :(得分:3)

您可以使用Conditions.SenderAddress规则条件并使用其地址属性,如下面的地址:

Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
Dim oAddressRuleCondition As Outlook.AddressRuleCondition

Set colRules = Application.Session.DefaultStore.GetRules()
Set oRule = colRules.Create("Sender Rule", olRuleReceive)
Set oAddressRuleCondition = oRule.Conditions.SenderAddress

With oAddressRuleCondition 

    .Enabled = True
    .Address = Array("example")

End With

.....

colRules.Save