Now I'm creating an java app that have to retrieve deleted emails in outlook mailbox, I tried JavaMail API but seems it can only retrieve mails that exist in mailBox, so is there any way/Java APIs to read Exchange DB to retrieve those deleted mails? any suggestions or ideas are much appreciated.
Asked
Active
Viewed 4,627 times
1
-
Do you want to restore them out of the recycl bin, or fully deleted? – Khinsu Aug 07 '13 at 04:41
-
Do you have any ideas? Thanks for your attention. – user2659197 Aug 07 '13 at 04:46
-
@ user2659197 : you should contact administrator. There may be a backup copy/archived copies. In some cases, there are legal requirement to save all mails for quite some time. You may ask this is in superuser/serverfault site – Jayan Aug 07 '13 at 04:56
-
http://stackoverflow.com/questions/1739921/are-there-any-api-to-integrate-microsoft-exchange-server-with-java-application-f/7517021#7517021 – Aug 08 '13 at 10:41
1 Answers
2
Microsoft released a Java Api for exchange .
http://blogs.msdn.com/b/exchangedev/archive/2013/01/03/ews-java-api-1-2-get-started.aspx
From this API we can get the mails from any folder including deleted items,purges etc..,
Sample code :
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials(userName, password);
service.setCredentials(credentials);
service.autodiscoverUrl(autoDiscoverUrl);
service.setTraceEnabled(true);
ItemView view = new ItemView(20);
FindItemsResults<Item> findResults;
do {
findResults = service.findItems(WellKnownFolderName.RecoverableItemsDeletions, view);
for (Item item : findResults.getItems()) {
System.out.println(item);
}
view.setOffset(view.getOffset() + 20);
} while (findResults.isMoreAvailable());
WellKnownFolderName enum contains all folders.

SANN3
- 9,459
- 6
- 61
- 97
-
Thanks very much, it works fine for me. but why I cannot get any records using WellKnownFolderName.RecoverableItemsPurges as I have purged some mails in OutLook? – user2659197 Aug 07 '13 at 09:21
-
If you enable Litigation hold or In place preservation then only Purges folder contains mails. Otherwise exchange will delete the items, not move to purge folder. If you think this is answer mark it as answer. – SANN3 Aug 07 '13 at 10:02
-
Thanks very much!,one more question, if mails are fully deleted, are they archived into a folder of exchange server? How to find them? – user2659197 Aug 08 '13 at 03:30
-
That folders are not visible. Using power shell only we can view the count and details. There is no UI for that. – SANN3 Aug 08 '13 at 04:17
-
Thanks, So you mean we cannot access that folder via APIs, right? For the deleted mails, We can only access in Deletions or Purges folder? – user2659197 Aug 08 '13 at 04:41
-
If we delete any mail it will move to deleted items. From deleted items if we delete means it will move to recoverable items.From recoverable items if we delete means it will move to purges if Litigation hold or Inplace preservation is enabled. We can access all these folders via API. – SANN3 Aug 08 '13 at 05:30
-
But how to access mails that are deleted in purges if Litigation hold or Inplace preservation is enabled? – user2659197 Aug 08 '13 at 05:44
-
-
Thanks! So any ways to access backup copy/archived copies of mails deleted from purges? – user2659197 Aug 08 '13 at 05:53