Move Messages from One Folder to Another using WebDav
Contents
[
Hide
]
You can move email messages from one folder to another with the help of the ExchangeClient.moveMessage() method. It takes the parameters:
- The unique URI of the message which is to be moved.
- The unique URI of the destination folder.
Move Messages between Folders
The sample code below that moves a message in a mailbox from the Inbox folder to a folder called Processed. In this example, the application:
- Reads messages from the Inbox folder.
- Processes some of the messages based on some criteria (in this example, we find a keyword in the message subject).
- Moves messages which fulfill the given condition to the Processed folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
String mailboxURI = "http://ex2003/exchange/administrator"; // WebDAV | |
ExchangeClient client = new ExchangeClient(mailboxURI, "username", "password", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo(); | |
// List all messages from Inbox folder | |
System.out.println("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.listMessages(mailboxInfo.getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : msgInfoColl) { | |
// Move message to "Processed" folder, after processing certain messages based on some criteria | |
if (msgInfo.getSubject() != null && msgInfo.getSubject().contains("process this message") == true) { | |
// Move it | |
client.moveMessage(msgInfo, client.getMailboxInfo().getRootUri() + "/Processed/" + msgInfo.getSubject()); | |
System.out.println("Message moved...." + msgInfo.getSubject()); | |
} else { | |
// Do something else | |
} | |
} |