Docs API Reference

Activation rules for Outlook add-ins

Outlook activates some types of add-ins if the message or appointment that the user is reading or composing satisfies the activation rules of the add-in. This is true for all add-ins that use the 1.1 manifest schema. The user can then choose the add-in from the Outlook UI to start it for the current item.

The following figure shows Outlook add-ins activated in the add-in bar for the message in the Reading Pane.

App bar showing activated read mail apps

Specify activation rules in a manifest

To have Outlook activate an add-in for specific conditions, specify activation rules in the add-in manifest by using one of the following Rule elements:

Note: The Rule element that you use to specify an individual rule is of the abstract Rule complex type. Each of the following types of rules extends this abstract Rule complex type. So when you specify an individual rule in a manifest, you must use the xsi:type attribute to further define one of the following types of rules. For example, the following rule defines an ItemIs rule: <Rule xsi:type="ItemIs" ItemType="Message" /> The FormType attribute applies to activation rules in the manifest v1.1 but is not defined in VersionOverrides v1.0. So it can't be used when ItemIs is used in the VersionOverrides node.

The following table lists the types of rules that are available. You can find more information following the table and in the specified articles under Create Outlook add-ins for read forms.

Rule name Applicable forms Description
ItemIs Read ,Compose Checks to see whether the current item is of the specified type (message or appointment). Can also check the item class and form type.and optionally, item message class.
ItemHasAttachment Read Checks to see whether the selected item contains an attachment.
ItemHasKnownEntity Read Checks to see whether the selected item contains one or more well-known entities. More information: Match strings in an Outlook item as well-known entities.
ItemHasRegularExpressionMatch Read Checks to see whether the sender's email address, the subject, and/or the body of the selected item contains a match to a regular expression.More information: Use regular expression activation rules to show an Outlook add-in.
RuleCollection Read, Compose Combines a set of rules so that you can form more complex rules.

ItemIs rule

The ItemIs complex type defines a rule that evaluates to true if the current item matches the item type, and optionally the item message class if it's stated in the rule.

Specify one of the following item types in the ItemType attribute of an ItemIs rule. You can specify more than one ItemIs rule in a manifest. The ItemType simpleType defines the types of Outlook items that support Outlook add-ins.

Value Description
Appointment Specifies an item in an Outlook calendar. This includes a meeting item that has been responded to and has an organizer and attendees, or an appointment that does not have an organizer or attendee and is simply an item on the calendar.This corresponds to the IPM.Appointment message class in Outlook.
Message Specifies one of the following items received in typically the Inbox:
  • An email message. This corresponds to the IPM.Note message class in Outlook.

  • A meeting request, response, or cancellation. This corresponds to the following message classes in Outlook:

    IPM.Schedule.Meeting.Request

    IPM.Schedule.Meeting.Neg

    IPM.Schedule.Meeting.Pos

    IPM.Schedule.Meeting.Tent

    IPM.Schedule.Meeting.Canceled

The FormType attribute is used to specify the mode (read or compose) in which the add-in should activate.

**Note: ** The ItemIs FormType attribute is defined in schema v1.1 and later but not in VersionOverrides v1.0. Do not include the FormType attribute when defining add-in commands.

After an add-in is activated, you can use the mailbox.item property to obtain the currently selected item in Outlook, and the item.itemType property to obtain the type of the current item.

You can optionally use the ItemClass attribute to specify the message class of the item, and the IncludeSubClasses attribute to specify whether the rule should be true when the item is a subclass of the specified class.

For more information about message classes, see Item Types and Message Classes.

The following example is an ItemIs rule that lets users see the add-in in the Outlook add-in bar when the user is reading a message:

<Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />

The following example is an ItemIs rule that lets users see the add-in in the Outlook add-in bar when the user is reading a message or appointment.

<Rule xsi:type="RuleCollection" Mode="Or">
  <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
  <Rule xsi:type="ItemIs" ItemType="Appointment" FormType="Read" />
</Rule>

ItemHasAttachment rule

The ItemHasAttachment complex type defines a rule that checks if the selected item contains an attachment.

<Rule xsi:type="ItemHasAttachment" />

ItemHasKnownEntity rule

Before an item is made available to an add-in, the server examines it to determine whether the subject and body contain any text that is likely to be one of the known entities. If any of these entities are found, it is placed in a collection of known entities that you access by using the getEntities or getEntitiesByType method of that item.

You can specify a rule by using ItemHasKnownEntity that shows your add-in when an entity of the specified type is present in the item. You can specify the following known entities in the EntityType attribute of an ItemHasKnownEntity rule: - Address - Contact - EmailAddress - MeetingSuggestion - PhoneNumber - TaskSuggestion - URL

You can optionally include a regular expression in the RegularExpression attribute so that your add-in is only shown when an entity that matches the regular expression in present. To obtain matches to regular expressions specified in ItemHasKnownEntity rules, you can use the getRegExMatches or getFilteredEntitiesByName method for the currently selected Outlook item.

The following example shows a collection of Rule elements that show the add-in when one of the specified well-known entities is present in the message.

<Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemHasKnownEntity" EntityType="Address" />
    <Rule xsi:type="ItemHasKnownEntity" EntityType="MeetingSuggestion" />
    <Rule xsi:type="ItemHasKnownEntity" EntityType="TaskSuggestion" />
</Rule>

The following example shows an ItemHasKnownEntity rule with a RegularExpression attribute that activates the add-in when a URL that contains the word "contoso" is present in a message.

<Rule xsi:type="ItemHasKnownEntity" EntityType="Url" RegularExpression="contoso" />

For more information about entities in activation rules, see Match strings in an Outlook item as well-known entities.

ItemHasRegularExpressionMatch rule

The ItemHasRegularExpressionMatch complex type defines a rule that uses a regular expression to match the contents of the specified property of an item. If text that matches the regular expression is found in the specified property of the item, Outlook activates the add-in bar and displays the add-in. You can use the getRegExMatches or getRegExMatchesByName method of the object that represents the currently selected item to obtain matches for the specified regular expression.

The following example shows an ItemHasRegularExpressionMatch that activates the add-in when the body of the selected item contains "apple", "banana", or "coconut", ignoring case.

<Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="fruits" RegExValue="apple|banana|coconut" pPropertyName="BodyAsPlaintext" IgnoreCase="true" />

For more information about using the ItemHasRegularExpressionMatch rule, see Use regular expression activation rules to show an Outlook add-in.

RuleCollection rule

The RuleCollection complex type combines multiple rules into a single rule. You can specify whether the rules in the collection should be combined with a logical OR or a logical AND by using the Mode attribute.

When a logical AND is specified, an item must match all the specified rules in the collection to show the add-in. When a logical OR is specified, an item that matches any of the specified rules in the collection will show the add-in.

You can combine RuleCollection rules to form complex rules. The following example activates the add-in when the user is viewing an appointment or message item and the subject or body of the item contains an address.

<Rule xsi:type="RuleCollection" Mode="And">
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
    <Rule xsi:type="ItemIs" ItemType="Appointment" FormType="Read"/>
  </Rule>
  <Rule xsi:type="ItemHasKnownEntity" EntityType="Address" />
</Rule>

The following example activates the add-in when the user is composing a message, or when the user is viewing an appointment and the subject or body of the appointment contains an address.

<Rule xsi:type="RuleCollection" Mode="Or"> 
  <Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" /> 
  <Rule xsi:type="RuleCollection" Mode="And">
    <Rule xsi:type="ItemIs" ItemType="Appointment" FormType="Read" />
    <Rule xsi:type="ItemHasKnownEntity" EntityType="Address" />
  </Rule> 
</Rule>

Limits for rules and regular expressions

To provide a satisfactory experience with Outlook add-ins, you should adhere to the activation and API usage guidelines. The following table shows general limits for regular expressions and rules but there are specific rules for different hosts. For more information, see Limits for activation and JavaScript API for Outlook add-ins and Troubleshoot Outlook add-in activation.

Add-in element Guidelines
Manifest Size No larger than 256 KB.
Rules No more than 15 rules.
ItemHasKnownEntity An Outlook rich client will apply the rule against the first 1 MB of the body, and not to the rest of the body.
Regular Expressions For ItemHasKnownEntity or ItemHasRegularExpressionMatch rules for all Outlook hosts:
  • Specify no more than 5 regular expressions in activation rules for an Outlook add-in. You cannot install an add-in if you exceed the that limit.
  • Specify regular expressions whose anticipated results are returned by the getRegExMatches method call within the first 50 matches.
  • Specify look-ahead assertions in regular expressions, but not look-behind, (?<=text), and negative look-behind (?<!text).
  • Specify regular expressions whose match does not exceed the limits in the table below.

    Limit on length of a regex matchOutlook rich clientsOutlook Web App for Devices
    Item body is plain text1.5 KB3 KB
    Item body it HTML3 KB3 KB

Additional resources