Java---使用EWS读取exchange邮件
2020-12-13 05:02
阅读:474
标签:http list logging rom htm mpi 时间 地址 red
第一步:
下载EWS API相关包:
从如下路径下载EWS API包:http://code.msdn.microsoft.com/Exchange-EWS-Java-API-12-1a5a1143
第二步:
导入依赖:
- Apache Commons HttpClient 3.1 (commons-httpclient-3.1.jar)
- Apache Commons Codec 1.4 (commons-codec-1.4.jar)
- Apache Commons Logging 1.1.1 (commons-codec-1.4.jar)
- JCIFS 1.3.15 (jcifs-1.3.15.jar)
(或者导入pom.xml):
ReadEmail
UTF-8 1.6 1.4.7 1.7.3 3.8.1 javax.mail
mail
${mail.version} compile org.jsoup
jsoup
${jsoup.version} commons-httpclient
commons-httpclient
3.1 commons-codec
commons-codec
1.4 jcifs
jcifs
1.3.17 commons-logging
commons-logging
1.1.1 microsoft.exchange.webservices
EWSJavaAPI
1.2 junit
junit
${junit.version} test ReadEmail
第三步:
代码示例:
public class ReadExchangeMail{
public static void main(String[] args){
//使用exchange服务工具类创建服务
//ExchangeMailUtil exchangeMailUtil = new ExchangeMailUtil(mailServer, user, password, readUrlPrefix);
//ExchangeService service = exchangeMailUtil.getExchangeService();
//创建exchange服务 ExchangeVersion.Exchange2007_SP1 (服务版本号)
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials("用户名", "密码", "域");
service.setCredentials(credentials);
service.setUrl(new URI("https://"+"邮箱服务器地址"+"/EWS/Exchange.asmx"));
// Bind to the Inbox.
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
System.out.println(inbox.getDisplayName());
ItemView view = new ItemView(10);
// 查询
FindItemsResults- findResults = service.findItems(inbox.getId(), itemView);
ArrayList
- items = findResults.getItems();
for(int i=0;i
" +items.get(i).getSubject());
System.out.println(“接收方:”+message.getReceivedBy());
System.out.println("发送:"+message.getSender());
System.out.println("发送人:"+message.getFrom());
System.out.println("接收时间:"+items.get(i).getDateTimeReceived());
System.out.println("是否已读:"+message.getIsRead());
System.out.println("邮件ID:"+items.get(i).getId());
}
}
}
##:Java---关于如何使用EWS 写个ExchangeMailUtil 详见 :
https://www.cnblogs.com/itczybk/articles/11011744.html
Java---使用EWS读取exchange邮件
标签:http list logging rom htm mpi 时间 地址 red
原文地址:https://www.cnblogs.com/itczybk/p/11128469.html
评论
亲,登录后才可以留言!