I am trying to connect to my organization outlook account. Initially I was facing some error with autodiscover
The Autodiscover service couldn't be located
Therefore I commented out the line and used the url webservice url that is provided to me. But now I am getting the following error.
Exception in thread "main" microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The response received from the service didn't contain valid XML.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.internalCreateItems(ExchangeService.java:598)
at microsoft.exchange.webservices.data.core.ExchangeService.createItem(ExchangeService.java:657)
at microsoft.exchange.webservices.data.core.service.item.Item.internalCreate(Item.java:245)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.internalSend(EmailMessage.java:147)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.send(EmailMessage.java:258)
at xxx.yyy.zzz.data.ExchangeMailReceiver.main(ExchangeMailReceiver.java:46)
Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The response received from the service didn't contain valid XML.
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.readResponse(ServiceRequestBase.java:370)
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:63)
... 7 more
I am following what they have mentioned on their github page
This is the code that I am running
public class ExchangeMailReceiver {
static ExchangeService service = null;
public static void main(String[] args) throws Exception {
String emailAddress = "myemailid";
String password = "mypassword";
service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials(emailAddress, password);
service.setCredentials(credentials);
service.setUrl(new URI("https://xxx.yyy.zzz/owa/auth/logon.aspx?"));
// try {
// service.autodiscoverUrl(emailAddress, new RedirectionUrlCallback());
// } catch (Exception e) {
// e.printStackTrace();
// }
findChildFolders();
}
public static void findChildFolders() throws Exception {
FindFoldersResults findResults = service.findFolders(
WellKnownFolderName.Inbox, new FolderView(Integer.MAX_VALUE));
for (Folder folder : findResults.getFolders()) {
System.out.println("Count======" + folder.getChildFolderCount());
System.out.println("Name=======" + folder.getDisplayName());
}
}
class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
public boolean autodiscoverRedirectionUrlValidationCallback(
String redirectionUrl) {
return redirectionUrl.toLowerCase().startsWith("https://");
}
}