Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 5, 2022 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/8d8bb9d85c39778451f702fc5f12f454 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/8d8bb9d85c39778451f702fc5f12f454 to your computer and use it in GitHub Desktop.
Read Emails from Shared Mailbox on Exchange Server in Java
final String mailboxUri = "<HOST>";
final String domain = "";
final String username = "<EMAIL ADDRESS>";
final String password = "<PASSWORD>";
final String sharedEmail = "<SHARED EMAIL ADDRESS>";
// Setup network credentials
NetworkCredential credentials = new NetworkCredential(username, password, domain);
// Get EWS client
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
// Get items from inbox
String[] items = client.listItems(sharedEmail, "Inbox");
// Read each email message
for (String item : items) {
MapiMessage msg = client.fetchItem(item);
System.out.println("Subject:" + msg.getSubject());
System.out.println("Subject:" + msg.getBody());
}
client.dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment