当前位置: 首页 > 工具软件 > EWS Java API > 使用案例 >

Ews(ExchangeWebService)Api使用说明

龙景澄
2023-12-01

打个小广告:作者博客地址:http://nbsanke.top:68
本文未完善,持续更新中

Java EwsApi地址: GitHub链接

Ews 官方说明文档

接口说明地址: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)

Java Ews包引用

  1. Gradle引用
    dependencies {
        compile 'com.microsoft.ews-java-api:ews-java-api:2.0'
    }
    
  2. Maven引用
    <dependency>
        <groupId>com.microsoft.ews-java-api</groupId>
        <artifactId>ews-java-api</artifactId>
        <version>2.0</version>
    </dependency>
    

ExchangeService初始化

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);

Attachments(附件)

Autodiscover service(自动发现服务)

Automatic reply information(自动回复)

Availability(可用性)

Calendar items(日历项)

Contacts(联系人)

Conversations(会话)

Delegate access(委派授权)

Distribution lists(收信人列表)

Email messages(邮件信息)

Extended properties(扩展属性)

Folders(文件夹)

Items(项)

Notifications(通知)

Search(搜索)

Synchronization(同步)

Tasks(任务)

Inbox rules(收件箱规则)

 类似资料: