Create rule

Namespace: microsoft.graph

Create a messageRule object by specifying a set of conditions and actions.

Outlook carries out those actions if an incoming message in the user's Inbox meets the specified conditions.

Permissions

One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

Permission type Permissions (from least to most privileged)
Delegated (work or school account) MailboxSettings.ReadWrite
Delegated (personal Microsoft account) MailboxSettings.ReadWrite
Application MailboxSettings.ReadWrite

HTTP request

POST /me/mailFolders/inbox/messageRules
POST /users/{id | userPrincipalName}/mailFolders/inbox/messageRules

Request headers

Name Description
Authorization Bearer {token}. Required.

Request body

In the request body, supply the parameters that are applicable to your rule. The following are body parameters that are typically used when creating rules. You can specify any other writable messageRule properties as appropriate in the request body.

Name Type Description
actions messageRuleActions Actions to be taken on a message when the corresponding conditions, if any, are fulfilled. Required.
conditions messageRulePredicates Conditions that when fulfilled, will trigger the corresponding actions for that rule. Optional.
displayName String The display name of the rule. Required.
exceptions messageRulePredicates Represents exception conditions for the rule. Optional.
isEnabled Boolean Indicates whether the rule is enabled to be applied to messages. Optional.
sequence Int32 Indicates the order in which the rule is executed, among other rules. Required.

Response

If successful, this method returns 201 Created response code and a messageRule object in the response body.

Example

Request

Here is an example of the request.

POST https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules
Content-type: application/json

{
    "displayName": "From partner",
    "sequence": 2,
    "isEnabled": true,
    "conditions": {
        "senderContains": [
          "adele"
        ]
     },
     "actions": {
        "forwardTo": [
          {
             "emailAddress": {
                "name": "Alex Wilbur",
                "address": "AlexW@contoso.onmicrosoft.com"
              }
           }
        ],
        "stopProcessingRules": true
     }
}

Response

Here is an example of the response. Note: The response object shown here might be shortened for readability.

HTTP/1.1 201 Created
Content-type: application/json

{
  "id":"AQAAAJ5dZqA=",
  "displayName":"From partner",
  "sequence":2,
  "isEnabled":true,
  "hasError":false,
  "isReadOnly":false,
  "conditions":{
    "senderContains":[
      "ADELE"
    ]
  },
  "actions":{
      "stopProcessingRules":true,
      "forwardTo":[
        {
          "emailAddress":{
            "name":"Alex Wilbur",
            "address":"AlexW@contoso.onmicrosoft.com"
          }
        }
      ]
  }
}