Read the complete article on how to create and update inbox rules with EWS on MS Exchange Server in Java: https://blog.aspose.com/2022/04/13/manage-inbox-rules-on-exchange-server-in-java/
Last active
April 14, 2022 06:42
-
-
Save aspose-com-gists/654fcbd7a3342d45b4c993acc50ff036 to your computer and use it in GitHub Desktop.
Create and Update Inbox Rules on Exchange Server in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect to Exchange Server | |
IEWSClient client = EWSClient.getEWSClient(mailboxURI, credential); | |
System.out.println("Connected to Exchange server"); | |
// Create a new rule | |
InboxRule rule = new InboxRule(); | |
rule.setDisplayName("Message from client ABC"); | |
// Add conditions | |
RulePredicates newRules = new RulePredicates(); | |
// Set Subject contains string "ABC" and Add the conditions | |
newRules.containsSubjectStrings().addItem("ABC"); | |
newRules.getFromAddresses().addMailAddress(new MailAddress("administrator@ex2010.local", true)); | |
rule.setConditions(newRules); | |
// Add actions and Move the message to a folder | |
RuleActions newActions = new RuleActions(); | |
newActions.setMoveToFolder("120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="); | |
rule.setActions(newActions); | |
// Create rule | |
client.createInboxRule(rule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect to Exchange Server | |
IEWSClient client = EWSClient.getEWSClient(mailboxURI, credential); | |
System.out.println("Connected to Exchange server"); | |
// Get all inbox rules | |
InboxRule[] inboxRules = client.getInboxRules(); | |
// Loop through each rule | |
for (InboxRule inboxRule : inboxRules) { | |
if ("Message from client ABC".equals(inboxRule.getDisplayName())) { | |
// Update rule | |
inboxRule.getConditions().getFromAddresses().set_Item(0, new MailAddress("administrator@ex2010.local", true)); | |
client.updateInboxRule(inboxRule); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment