依赖的包
commons-codec-1.6.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
ews-java-api-2.0.jar
httpclient-4.5.2.jar
httpcore-4.4.4.jar
jcifs-1.3.15.jar
joda-time-2.1.jar
编写代码
public static void main(String[] args) throws Exception { //ExchangeService版本 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); //用户名、密码、域 ExchangeCredentials credentials = new WebCredentials("Administrator", "Admin123", "ZX"); service.setCredentials(credentials); //设置邮件服务器地址 service.setUrl(new URI("https://"+"mail.zx.com"+"/EWS/Exchange.asmx")); //创建过滤器 Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox); //创建过滤器条件,查询10封邮件 ItemView view = new ItemView(10); //查询 FindItemsResults<Item> findResults = service.findItems(inbox.getId(), view); for (Item item : findResults.getItems()) { EmailMessage message = EmailMessage.bind(service, item.getId()); message.load(); System.out.PRintln(message.getSender()); System.out.println("Sub -->" + item.getSubject()); } }
新闻热点
疑难解答