title | description | author | ms.localizationpriority | ms.subservice | doc_type |
---|---|---|---|---|---|
Create rule |
Create a messageRule object by specifying a set of conditions and actions. |
SuryaLashmiS |
medium |
outlook |
apiPageType |
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.
[!INCLUDE national-cloud-support]
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.
[!INCLUDE permissions-table]
POST /me/mailFolders/inbox/messageRules
POST /users/{id | userPrincipalName}/mailFolders/inbox/messageRules
Name | Description |
---|---|
Authorization | Bearer {token}. Required. Learn more about authentication and authorization. |
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. |
If successful, this method returns 201 Created
response code and a messageRule object in the response body.
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": "AlexW@contoso.com"
}
}
],
"stopProcessingRules": true
}
}
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
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":"AlexW@contoso.com"
}
}
]
}
}