public static void Run() { // Create and initialize credentials var credentials = new NetworkCredential("username", "12345"); // 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.MailboxInfo.TasksUri); // Parse all the tasks info in the list foreach (ExchangeMessageInfo info in tasks) { // Fetch task from exchange using current task info ExchangeTask task = client.FetchTask(info.UniqueUri); // Update the task status to NotStarted task.Status = ExchangeTaskStatus.NotStarted; // Set the task due date task.DueDate = new DateTime(2013, 2, 26); // Set task priority task.Priority = MailPriority.Low; // Update task on exchange client.UpdateTask(task); } Console.WriteLine(Environment.NewLine + "Task updated on Exchange Server successfully."); }
public static void Run() { // ExStart:FilterTasksFromServer // Set mailboxURI, Username, password, domain information string mailboxUri = "https://ex2010/ews/exchange.asmx"; string username = "******"; string password = "******"; string domain = "ex2010.local"; NetworkCredential credentials = new NetworkCredential(username, password, domain); IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); ExchangeQueryBuilder queryBuilder = null; MailQuery query = null; ExchangeTask fetchedTask = null; ExchangeMessageInfoCollection messageInfoCol = null; client.TimezoneId = "Central Europe Standard Time"; Array values = Enum.GetValues(typeof(ExchangeTaskStatus)); //Now retrieve the tasks with specific statuses foreach (ExchangeTaskStatus status in values) { queryBuilder = new ExchangeQueryBuilder(); queryBuilder.TaskStatus.Equals(status); query = queryBuilder.GetQuery(); messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); fetchedTask = client.FetchTask(messageInfoCol[0].UniqueUri); } //retrieve all other than specified foreach (ExchangeTaskStatus status in values) { queryBuilder = new ExchangeQueryBuilder(); queryBuilder.TaskStatus.NotEquals(status); query = queryBuilder.GetQuery(); messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); } //specifying multiple criterion ExchangeTaskStatus[] selectedStatuses = new ExchangeTaskStatus[] { ExchangeTaskStatus.Completed, ExchangeTaskStatus.InProgress }; queryBuilder = new ExchangeQueryBuilder(); queryBuilder.TaskStatus.In(selectedStatuses); query = queryBuilder.GetQuery(); messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); queryBuilder = new ExchangeQueryBuilder(); queryBuilder.TaskStatus.NotIn(selectedStatuses); query = queryBuilder.GetQuery(); messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); //ExEnd:FilterTasksFromServer }
public static void Run() { // ExStart:DeleteTaskOnExchange // 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.MailboxInfo.TasksUri); // Parse all the tasks info in the list foreach (ExchangeMessageInfo info in tasks) { // Fetch task from exchange using current task info ExchangeTask task = client.FetchTask(info.UniqueUri); // Check if the current task fulfills the search criteria if (task.Subject.Equals("test")) { //Delete task from exchange client.DeleteItem(task.UniqueUri, DeletionOptions.DeletePermanently); } } // ExEnd:DeleteTaskOnExchange }