Read the complete article on how to add, update, and delete tasks on MS Exchange Server in Java: https://blog.aspose.com/2022/03/11/create-update-or-delete-tasks-on-ms-exchange-server-in-java/
Last active
April 12, 2022 13:15
-
-
Save aspose-com-gists/f17a81214b8e111869e19ac9bc3188d6 to your computer and use it in GitHub Desktop.
Create, Update or Delete Tasks on MS 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
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create Exchange task object | |
ExchangeTask task = new ExchangeTask(); | |
// Set task subject and status (and other properties) | |
task.setSubject("New-Test"); | |
task.setStatus(ExchangeTaskStatus.InProgress); | |
// Create task | |
client.createTask(client.getMailboxInfo().getTasksUri(), task); |
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
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks' info collection from Exchange | |
ExchangeMessageInfoCollection tasks = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
// Parse all the tasks info objects in the list | |
for (ExchangeMessageInfo info : (Iterable<ExchangeMessageInfo>) tasks) { | |
// Fetch task from Exchange using current task info | |
ExchangeTask task = client.fetchTask(info.getUniqueUri()); | |
// Check if the current task fulfills the search criteria | |
if (task.getSubject().equals("test")) { | |
// Delete task from Exchange | |
client.deleteItem(task.getUniqueUri(), DeletionOptions.getDeletePermanently()); | |
} | |
} |
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
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from Exchange | |
ExchangeMessageInfoCollection tasks = client.listMessages(client.getMailboxInfo().getTasksUri()); | |
// Parse all the tasks info objects in the list | |
for (ExchangeMessageInfo info : (Iterable<ExchangeMessageInfo>) tasks) { | |
// Fetch task from Exchange using current task info | |
ExchangeTask task = client.fetchTask(info.getUniqueUri()); | |
// Update the task's status | |
task.setStatus(ExchangeTaskStatus.NotStarted); | |
// Set the task's due date | |
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
task.setDueDate(sdf.parse("26/02/2013 00:00:00")); | |
// Set task's priority | |
task.setPriority(MailPriority.Low.getValue()); | |
// Update task on Exchange | |
client.updateTask(task); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment