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.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new MessageRule
{
DisplayName = "From partner",
Sequence = 2,
IsEnabled = true,
Conditions = new MessageRulePredicates
{
SenderContains = new List<string>
{
"adele",
},
},
Actions = new MessageRuleActions
{
ForwardTo = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Name = "Alex Wilbur",
Address = "AlexW@contoso.onmicrosoft.com",
},
},
},
StopProcessingRules = true,
},
};
var result = await graphClient.Me.MailFolders["{mailFolder-id}"].MessageRules.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new MessageRule();
$requestBody->setDisplayName('From partner');
$requestBody->setSequence(2);
$requestBody->setIsEnabled(true);
$conditions = new MessageRulePredicates();
$conditions->setSenderContains(['adele', ]);
$requestBody->setConditions($conditions);
$actions = new MessageRuleActions();
$forwardToRecipient1 = new Recipient();
$forwardToRecipient1EmailAddress = new EmailAddress();
$forwardToRecipient1EmailAddress->setName('Alex Wilbur');
$forwardToRecipient1EmailAddress->setAddress('AlexW@contoso.onmicrosoft.com');
$forwardToRecipient1->setEmailAddress($forwardToRecipient1EmailAddress);
$forwardToArray []= $forwardToRecipient1;
$actions->setForwardTo($forwardToArray);
$actions->setStopProcessingRules(true);
$requestBody->setActions($actions);
$result = $graphServiceClient->me()->mailFolders()->byMailFolderId('mailFolder-id')->messageRules()->post($requestBody);