Skip to content

Instantly share code, notes, and snippets.

@aheld
Created July 14, 2013 19:48
Show Gist options
  • Save aheld/5995611 to your computer and use it in GitHub Desktop.
Save aheld/5995611 to your computer and use it in GitHub Desktop.
Connecting to Microsoft Exchange using Java to download email messages
import microsoft.exchange.webservices.data.*;
import java.net.URI;
public class Main {
public static void main(String [] args) throws Exception {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials("USER@DOMAIN.COM","PASSWORD");
service.setCredentials(credentials);
service.setUrl(new URI("https://EXCHANGE_SERVER_API_DOMAIN/ews/exchange.asmx"));
ItemView view = new ItemView (10);
FindItemsResults findResults = service.findItems(WellKnownFolderName.Inbox, view);
for(Item item : findResults.getItems()){
item.load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent));
System.out.println("id==========" + item.getId());
System.out.println("sub==========" + item.getSubject());
System.out.println("sub==========" + item.getMimeContent());
}
}
}
@manishdeo
Copy link

Hi there,

I am trying your example with below url
https://outlook.nousinfo.com/ews/Exchange.asmx

I am getting error "Error in Data source validation Exchange Server outlook.nousinfo.com".

Let me know if you have faced the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment