(一) .NET API 用于管理 MS Exchange Server 上的任务
在 MS Exchange Server 上创建、更新或删除任务,我们将使用Aspose.Email for .NET。它是一个功能丰富的 API,用于创建电子邮件客户端应用程序并与 MS Exchange Server 一起工作,而无需编写复杂的代码。您可以 下载 API 的 DLL 或 使用以下命令从NuGet安装它。
PM> Install-Package Aspose.Email
(二) 使用 C# 在 MS Exchange Server 上创建任务
以下是在 C# .NET 中在 MS Exchange Server 上创建任务的步骤。
- 首先,连接到 Exchange Server 并将 EWS 客户端的实例放入 IEWSClient 对象中。
- 然后,创建ExchangeTask类的实例。
- 设置任务的属性,例如主题、状态等。
- 最后,使用IEWSClient.CreateTask(IEWSClient.MailboxInfo.TasksUri, ExchangeTask)方法创建任务。
以下代码示例展示了如何使用 C# 在 MS Exchange Server 上创建任务。
// Create instance of EWSClient class by giving credentialsIEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");// Create Exchange task objectExchangeTask task = new ExchangeTask();// Set task subject and status (or other properties)task.Subject = "New-Test";task.Status = ExchangeTaskStatus.InProgress;// Create taskclient.CreateTask(client.MailboxInfo.TasksUri, task);
(三) 在 C# 中更新 MS Exchange 服务器上的任务
您还可以使用 C# 以编程方式访问和更新 MS Exchange Server 上的现有任务。以下是执行此操作的步骤。
- 首先,连接到 Exchange Server 并将 EWS 客户端的实例放入 IEWSClient 对象中。
- 然后,使用IEWSClient.ListMessages(IEWSClient.MailboxInfo.TasksUri)方法将任务列表获取到ExchangeMes sageInfoCollection 对象中。
- 循环遍历集合中的每个ExchangeMes sageInfo。
- 使用IEWSClient.FetchTask(ExchangeMessageInfo.UniqueUri)方法获取每个ExchangeTask并过滤所需的。
以下代码示例显示了如何在 C# 中更新 MS Exchange Server 上的任务。
// Create and initialize credentialsvar credentials = new NetworkCredential("username", "12345");// Create instance of ExchangeClient class by giving credentialsIEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");// Get tasks info collection from exchangeExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri);// Parse all the tasks in the listforeach (ExchangeMessageInfo info in tasks){// Fetch task from exchange using current task infoExchangeTask task = client.FetchTask(info.UniqueUri);// Update the task statustask.Status = ExchangeTaskStatus.NotStarted;// Set the task due datetask.DueDate = new DateTime(2013, 2, 26);// Set task prioritytask.Priority = MailPriority.Low;// Update task on exchangeclient.UpdateTask(task);}
(四) 在 C# 中删除 MS Exchange Server 上的任务
以下是在 C# 中删除 MS Exchange 服务器上的任务的步骤。
- 首先,连接到 Exchange Server 并将 EWS 客户端的实例放入 IEWSClient 对象中。
- 然后,使用IEWSClient.ListMessages(IEWSClient.MailboxInfo.TasksUri)方法将任务列表获取到ExchangeMes sageInfoCollection 对象中
- 循环遍历集合中的每个ExchangeMes sageInfo。
- 使用IEWSClient.FetchTask(ExchangeMessageInfo.UniqueUri)方法获取每个ExchangeTask并过滤所需的。
- 最后,使用IEWSClient.DeleteItem(ExchangeTask.UniqueUri, DeletionOptions.DeletePermanently)方法删除任务。
以下代码示例展示了如何在 C# 中从 MS Exchange Server 中删除任务。
// Create instance of ExchangeClient class by giving credentialsIEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");// Get tasks collection from exchangeExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri);// Parse all the tasks in the listforeach (ExchangeMessageInfo info in tasks){// Fetch task from exchange using current task infoExchangeTask task = client.FetchTask(info.UniqueUri);// Check if the current task fulfills the criteriaif (task.Subject.Equals("test")){// Delete task from exchangeclient.DeleteItem(task.UniqueUri, DeletionOptions.DeletePermanently);}}
结论
欢迎下载|体验更多Aspose产品
获取更多信息请咨询在线客服 或 加入Aspose技术交流群()
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!