I am writing an application which has to get items that can be matched with rules.
//new messages goes here
void items_ItemAdd(object Item)
{
//all rules
Rules rules = Application.Session.DefaultStore.GetRules();
Outlook.MailItem mail = (Outlook.MailItem)Item;
if (mail != null)
{
// I need to find out if mail matches with one of the rule. And handle in an appropriate way.
}
}
The only way to check which rules apply to which items is by enumerating the Rule Conditions (and excluding rule exceptions) manually for each
MailItem. The rule engine works by executing each rule you have defined viaRule.Execute– it doesn’t provide a mechanism to preview affected items.Here is an (untested) example for reference on how to match a contains subject rule (
olConditionSubject). You would also need to handle other Rule Conditions types.