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.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) MailboxSettings.ReadWrite Not available.
Delegated (personal Microsoft account) MailboxSettings.ReadWrite Not available.
Application MailboxSettings.ReadWrite Not available.

HTTP request

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

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.

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

The following example shows a 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": "[email protected]"
              }
           }
        ],
        "stopProcessingRules": true
     }
}

Response

The following example shows 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":"[email protected]"
          }
        }
      ]
  }
}