Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 12, 2022 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/f17a81214b8e111869e19ac9bc3188d6 to your computer and use it in GitHub Desktop.
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
// 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);
// 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());
}
}
// 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