打个小广告:作者博客地址:http://nbsanke.top:68
本文未完善,持续更新中
接口说明地址:https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.exchange.webservices.data?view=exchange-ews-api
c#版Api教程及案例说明地址:https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633710(v%3Dexchg.80)
dependencies {
compile 'com.microsoft.ews-java-api:ews-java-api:2.0'
}
com.microsoft.ews-java-api
ews-java-api
2.0
ExchangeService是Ews(ExchangeWebService)接口调用基础,如果想要调用Ews所有相关接口必须以ExcahngeService为基础
ExchangeService初始化分为三个步骤:
1.创建ExchangeService对象,需传入当前Exchange服务版本。目前Ews可选ExchangeService版本有以下几个版本
1) Exchange2007_SP1
2) Exchange2010
3) Exchange2010_SP1
4) Exchange2010_SP2
创建ExchangeService对象代码示例:
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
2.创建ExchangeCredentials对象。ExchangeCredentials是ExchangeService信任凭据对象,所以在初始化的时候需要传入身份相关信息。
创建ExchangeCredentials对象示例代码:
ExchangeCredentials exchangeCredentials = new WebCredentials(username, password);
3.为ExchangeService设置信任凭据,ExchangeService服务Url
示例代码:
exchangeService.setCredentials(exchangeCredentials);
exchangeService.setUrl(new URI("ExhcangeWebService服务Url"));
exchangeService.setTraceEnabled(true);
在这里特别说明一下,如果您不想设置Url,您可以采用ExchangeService自动发现,这也是Ews推荐方式
示例代码如下:
exchangeService.autodiscoverUrl("ExchangeWebService所在域");
初始化代码合并起来如下:
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials exchangeCredentials = new WebCredentials(username, password);
exchangeService.setCredentials(exchangeCredentials);
exchangeService.setUrl(new URI(ewsConfigProperties.getServerUrl()));
exchangeService.setTraceEnabled(true);