Delete Messages from Exchange Server using WebDav
Contents
[
Hide
]
You can delete email messages from a folder with the help of the ExchangeClient.deleteMessage() method. It takes the message’s unique URI as a parameter.
The sample code below deletes a message from the Inbox folder. For the purpose of this example, the code:
- Reads messages from the Inbox folder.
- Process messages based on some criteria (in this example, we find a keyword in the message subject).
- Delete the message.
This file contains hidden or 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 | |
ExchangeClient client = new ExchangeClient("http://ex2003/exchange/administrator", "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) { | |
// Delete message based on some criteria | |
if (msgInfo.getSubject() != null && msgInfo.getSubject().contains("delete") == true) { | |
// Delete it | |
client.deleteMessage(msgInfo.getUniqueUri()); | |
System.out.println("Message deleted...." + msgInfo.getSubject()); | |
} else { | |
// Do something else | |
} | |
} |