ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ExchangeCredentials credentials = new WebCredentials("xxx", "xxx");
service.setUrl(new URI("https://mail.xxx.com/EWS/Exchange.asmx"));
service.setCredentials(credentials);
Folder msgFolderRoot = Folder.bind(service, WellKnownFolderName.Root);
int childFolderCount = msgFolderRoot.getChildFolderCount();
FolderView folderView = new FolderView(childFolderCount);
FindFoldersResults findResults = msgFolderRoot.findFolders(folderView);
for (Folder folder : findResults.getFolders()) {
System.out.println("Count======" + folder.getChildFolderCount());
System.out.println("Name=======" + folder.getDisplayName());
}
Log:
Exception in thread "main" microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: No mailbox with such guid.
at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278)
at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165)
at microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:504)
at microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:523)
at microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:98)
at microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:147)
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); ExchangeCredentials credentials = new WebCredentials("xxx", "xxx"); service.setUrl(new URI("https://mail.xxx.com/EWS/Exchange.asmx")); service.setCredentials(credentials); Folder msgFolderRoot = Folder.bind(service, WellKnownFolderName.Root); int childFolderCount = msgFolderRoot.getChildFolderCount(); FolderView folderView = new FolderView(childFolderCount); FindFoldersResults findResults = msgFolderRoot.findFolders(folderView); for (Folder folder : findResults.getFolders()) { System.out.println("Count======" + folder.getChildFolderCount()); System.out.println("Name=======" + folder.getDisplayName()); }
Log: Exception in thread "main" microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: No mailbox with such guid. at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278) at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267) at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165) at microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:504) at microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:523) at microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:98) at microsoft.exchange.webservices.data.core.service.folder.Folder.bind(Folder.java:147)