(一) 在 MS Exchange Server 上处理对话的 C# .NET API
为了管理 Microsoft Exchange Server 上的对话,我们将使用 Aspose.Email for .NET。它是一个强大的 API,提供了一系列功能来实现电子邮件客户端应用程序。此外,它还允许您无缝访问 MS Exchange Server 的各种服务。您可以 下载 API 的 DLL 或 使用以下命令从NuGet安装它。
PM> Install-Package Aspose.Email
(二) 在 C# 中查找 MS Exchange Server 上的对话
以下是在 C# 中从 MS Exchange Server 中的文件夹中查找对话的步骤。
- 首先,使用用户名、密码和域创建并初始化 NetworkCredential对象。
- 然后, 使用邮箱 URI 和 NetworkCredential 对象初始化IEWSClient 。
- 调用IEWSClient.FindConversations(IEWSClient.MailboxInfo.InboxUri)方法并在ExchangeConversation数组中获取对话。
- 最后,遍历数组中的每个ExchangeConversation对象并检索其详细信息。
以下代码示例显示了如何在 C# 中从 MS Exchange Server 中的文件夹中查找对话。
string mailboxUri = "https://ex2010/ews/exchange.asmx";string username = "test.exchange";string password = "pwd";string domain = "ex2010.local";NetworkCredential credentials = new NetworkCredential(username, password, domain);// Connect to MS Exchange ServerIEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);Console.WriteLine("Connected to Exchange");// Get conversations from inboxExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);// Show all conversationsforeach (ExchangeConversation conversation in conversations){// Display conversation properties like Id and TopicConsole.WriteLine("Topic: " + conversation.ConversationTopic);Console.WriteLine("Flag Status: " + conversation.FlagStatus.ToString());Console.WriteLine();}
(三) 在 C# 中复制 MS Exchange Server 上的对话
您还可以将对话从一个文件夹复制到另一个文件夹,而无需编写复杂的代码。为了演示,让我们看看如何在 C# .NET 中将对话从收件箱复制到 Exchange Server 的已删除项目文件夹。
- 首先,使用用户名、密码和域创建并初始化NetworkCredential对象。
- 然后, 使用邮箱 URI 和 NetworkCredential 对象初始化IEWSClient 。
- 调用IEWSClient.FindConversations(IEWSClient.MailboxInfo.InboxUri)方法并在ExchangeConversation数组中获取对话。
- 循环遍历数组中的每个ExchangeConversation并过滤所需的。
- 最后使用IEWSClient.CopyConversationItems(ExchangeConversation.ConversationId, client.MailboxInfo.DeletedItemsUri)方法复制对话。
以下代码示例显示如何使用 C# .NET 在 MS Exchange Server 中复制对话。
string mailboxUri = "https://ex2010/ews/exchange.asmx";string username = "test.exchange";string password = "pwd";string domain = "ex2010.local";NetworkCredential credentials = new NetworkCredential(username, password, domain);// Connect to MS Exchange ServerIEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);Console.WriteLine("Connected to Exchange");// Get conversationsExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);foreach (ExchangeConversation conversation in conversations){Console.WriteLine("Topic: " + conversation.ConversationTopic);// Copy the conversation item based on some conditionif (conversation.ConversationTopic.Contains("test email") == true){client.CopyConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri);Console.WriteLine("Copied the conversation item to another folder");}}
(四) 在 C# 中移动 MS Exchange 服务器上的对话
在上一节中,我们只是将对话从一个文件夹复制到另一个文件夹。但是,在某些情况下,您可能需要将对话移至特定文件夹。以下是在 C# .NET 中在 MS Exchange Server 中移动对话的步骤。
- 首先,使用用户名、密码和域创建并初始化NetworkCredential对象。
- 然后, 使用邮箱 URI 和 NetworkCredential 对象初始化IEWSClient 。
- 调用IEWSClient.FindConversations(IEWSClient.MailboxInfo.InboxUri)方法并在ExchangeConversation数组中获取对话。
- 循环遍历数组中的每个ExchangeConversation并过滤所需的。
- 最后使用IEWSClient.MoveConversationItems(ExchangeConversation.ConversationId, client.MailboxInfo.DeletedItemsUri)方法移动对话。
以下代码示例显示了如何使用 C# .NET 在 MS Exchange Server 中移动对话。
string mailboxUri = "https://ex2010/ews/exchange.asmx";string username = "test.exchange";string password = "pwd";string domain = "ex2010.local";NetworkCredential credentials = new NetworkCredential(username, password, domain);// Connect to MS Exchange ServerIEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);Console.WriteLine("Connected to Exchange");// Get conversationsExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);foreach (ExchangeConversation conversation in conversations){Console.WriteLine("Topic: " + conversation.ConversationTopic);// Move the conversation item based on some conditionif (conversation.ConversationTopic.Contains("test email") == true){client.MoveConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri);Console.WriteLine("Moved the conversation item to another folder");}}
(五) 在 C# 中删除 MS Exchange Server 上的对话
最后但并非最不重要的一点,让我们看看如何在 C# 中从 MS Exchange Server 中删除对话。
- 首先,使用用户名、密码和域创建并初始化NetworkCredential对象。
- 然后, 使用邮箱 URI 和 NetworkCredential 对象初始化IEWSClient 。
- 之后,调用IEWSClient.FindConversations(IEWSClient.MailboxInfo.InboxUri)方法并在ExchangeConversation数组中获取对话。
- 循环遍历数组中的每个ExchangeConversation并过滤所需的。
- 最后,使用IEWSClient.DeleteConversationItems(ExchangeConversation.ConversationId)方法删除对话。
以下代码示例显示了如何在 C# .NET 中从 MS Exchange Server 中删除对话。
string mailboxUri = "https://ex2010/ews/exchange.asmx";string username = "test.exchange";string password = "pwd";string domain = "ex2010.local";NetworkCredential credentials = new NetworkCredential(username, password, domain);// Connect to MS Exchange ServerIEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);Console.WriteLine("Connected to Exchange");// Get conversationsExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri);foreach (ExchangeConversation conversation in conversations){Console.WriteLine("Topic: " + conversation.ConversationTopic);// Delete the conversation item based on some conditionif (conversation.ConversationTopic.Contains("test email") == true){client.DeleteConversationItems(conversation.ConversationId);Console.WriteLine("Deleted the conversation item");}}
(六) 在 C# 中删除 MS Exchange Server 上的对话
欢迎下载|体验更多Aspose产品
获取更多信息请咨询在线客服 或 加入Aspose技术交流群()

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!