Manage Inbox Rules on Exchange Server in C#

Manage Inbox Rules on Exchange Server in C#

Microsoft Exchange Server allows you to define different rules for the inbox, which are applied to the messages such as moving a message to a folder, deleting a message, etc. While working with the Exchange services from within .NET applications, you may need to manage inbox rules programmatically. In this article, you will learn how to create and update inbox rules on MS Exchange Server in C# .NET.

.NET API to Manage Inbox Rules on Exchange Server

To create and update inbox rules on MS Exchange Server, we will use Aspose.Email for .NET. The API makes it quite easier to seamlessly work with MS Exchange Server. You can either download the API’s DLL or install it from NuGet using the following command.

PM> Install-Package Aspose.Email

Create Inbox Rules on Exchange Server in C#

Aspose.Email for .NET uses Exchange Web Services (EWS) to work with inbox rules on Exchange Server. The following are the steps to create inbox rules on Exchange Server in C#.

The following code sample shows how to create an inbox rule on Exchange Server in C#.

Update Inbox Rules on Exchange Server in C#

The following are the steps to fetch and update an existing inbox rule on Exchange Server in C#.

  • First, connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
  • Then, call the IEWSClient.GetInboxRules() method to get all the rules in an InboxRule array.
  • Loop through each InboxRule in the array.
  • Filter the required rules based on some conditions.
  • Update the rule’s conditions or actions.
  • Finally, call IEWSClient.UpdateInboxRule(InboxRule) method to update the inbox rule.

The following code sample shows how to update an inbox rule on MS Exchange Server in C#.

Get a Free API License

You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.

Conclusion

In this article, you have learned how to work with inbox rules on Microsoft Exchange Server from within .NET applications. With the help of code samples, you have seen how to add or update inbox rules on Exchange Server in C#. Besides, you can explore the documentation to read more about Aspose.Email for .NET. In addition, you can post your queries to our forum.

See Also