Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 31, 2022 07:42
Show Gist options
  • Save aspose-com-gists/6dc20fbc731592afcdc8e14707120f21 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6dc20fbc731592afcdc8e14707120f21 to your computer and use it in GitHub Desktop.
Find, copy, move, and delete conversations from Microsoft Exchange Server in Java
// Set mailbox URI, username, password, domain information
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);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange");
// Find conversation items in the inbox folder
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
// Show all conversations
for (ExchangeConversation conversation : conversations) {
System.out.println("Topic: " + conversation.getConversationTopic());
// Copy the conversation item based on some condition
if (conversation.getConversationTopic().contains("test email")) {
client.copyConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri());
System.out.println("Copied the conversation item to another folder");
}
}
// Set mailbox URI, username, password, domain information
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);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange");
// Find conversation items in the inbox folder
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
// Show all conversations
for (ExchangeConversation conversation : conversations) {
System.out.println("Topic: " + conversation.getConversationTopic());
// Delete the conversation item based on some condition
if (conversation.getConversationTopic().contains("test email") == true) {
client.deleteConversationItems(conversation.getConversationId());
System.out.println("Deleted the conversation item");
}
}
// Set mailbox URI, username, password, domain information
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);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange");
// Find conversation items in the inbox folder
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
// Show all conversations
for (ExchangeConversation conversation : conversations) {
// Display conversation properties like Id and Topic
System.out.println("Topic: " + conversation.getConversationTopic());
System.out.println("Flag Status: " + conversation.getFlagStatus());
System.out.println();
}
// Set mailbox URI, username, password, domain information
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);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange");
// Find conversation items in the inbox folder
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
// Show all conversations
for (ExchangeConversation conversation : conversations) {
System.out.println("Topic: " + conversation.getConversationTopic());
// Move the conversation item based on some condition
if (conversation.getConversationTopic().contains("test email") == true) {
client.moveConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri());
System.out.println("Moved the conversation item to another folder");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment