翻譯|使用教程|編輯:胡濤|2022-04-20 15:09:10.793|閱讀 211 次
概述:在本文中,您將學習如何使用 Java 在 MS Exchange Server 上創建和更新收件箱規則
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在使用Microsoft Exchange Server的服務時,您可能需要為收件箱文件夾定義不同的規則。這些規則適用于郵件,例如將郵件移動到文件夾、刪除郵件等。收件箱規則由條件和滿足條件時要執行的操作組成。在本文中,您將學習如何使用 Java 在 MS Exchange Server 上創建和更新收件箱規則。
要在 MS Exchange Server 上使用收件箱規則,我們將使用Aspose.Email for Java。該 API 旨在與 MS Exchange Server 無縫協作并管理其服務。您可以 下載 API 或使用以下 Maven 配置安裝它。
Repository:
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>//repository.aspose.com/repo/</url> </repository>
Dependency:
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-email</artifactId> <version>22.3</version> <classifier>jdk16</classifier> </dependency>
Aspose.Email for Java 使用 Exchange Web 服務 (EWS) 來處理 Exchange Server 上的收件箱規則。以下是使用 Java 在 Exchange Server 上創建收件箱規則的步驟。
以下代碼示例顯示了如何在 Java 中在 Exchange Server 上創建收件箱規則 。
// Connect to Exchange Server IEWSClient client = EWSClient.getEWSClient(mailboxURI, credential); System.out.println("Connected to Exchange server"); // Create a new rule InboxRule rule = new InboxRule(); rule.setDisplayName("Message from client ABC"); // Add conditions RulePredicates newRules = new RulePredicates(); // Set Subject contains string "ABC" and Add the conditions newRules.containsSubjectStrings().addItem("ABC"); newRules.getFromAddresses().addMailAddress(new MailAddress("administrator@ex2010.local", true)); rule.setConditions(newRules); // Add actions and Move the message to a folder RuleActions newActions = new RuleActions(); newActions.setMoveToFolder("120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="); rule.setActions(newActions); // Create rule client.createInboxRule(rule);
以下是在 Java 中獲取和更新 Exchange Server 上現有收件箱規則的步驟。
以下代碼示例顯示了如何在 Java 中更新 MS Exchange Server 上的收件箱規則。
// Connect to Exchange Server IEWSClient client = EWSClient.getEWSClient(mailboxURI, credential); System.out.println("Connected to Exchange server"); // Get all inbox rules InboxRule[] inboxRules = client.getInboxRules(); // Loop through each rule for (InboxRule inboxRule : inboxRules) { if ("Message from client ABC".equals(inboxRule.getDisplayName())) { // Update rule inboxRule.getConditions().getFromAddresses().set_Item(0, new MailAddress("administrator@ex2010.local", true)); client.updateInboxRule(inboxRule); } }
結論
在本文中,您學習了如何在 Java 應用程序中使用 Microsoft Exchange Server 上的收件箱規則。您已了解如何使用 Java 在 Exchange Server 上添加或更新收件箱規則。此外,您可以使用 文檔探索 Aspose.Email for Java 的功能。外,您可以通過在線客服或加入群聊提出您的問題。
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn