通过ews java api怎么自动获取exchange的邮件

Python018

通过ews java api怎么自动获取exchange的邮件,第1张

一、通过Exchange Web Service来读取

1、首先,在项目上添加Web Service引用,这个Web Service的URL 地址格式如:https:// Exchange邮件系统的服务器名/EWS/Exchange.asmx

2、引入如下命名空间:

using System.Net

using System.Net.Security

using System.Security.Cryptography.X509Certificates

3、编写代码读取邮件信息:

//忽略SSL证书请求必须的,不添加在执行时会报错,错误信息好像是(记不清了)“客户端响应错误………html / text”

ServicePointManager.ServerCertificateValidationCallback =

delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)

{ return true}

//创建Exchange服务绑定对象

ExchangeServiceBinding exchangeServer = new ExchangeServiceBinding()

//创建安全身份凭证

ICredentials creds = new NetworkCredential("username", "password", "domain")

//建立信任连接

exchangeServer.Credentials = creds

exchangeServer.Url = "https:// Exchange邮件系统的服务器名/EWS/Exchange.asmx"

这个异常表示有类型转换错误,有个地方需要使用 javax.mail.Multipart 类型的对象,你用了 com.sun.mail.imap.IMAPInputStream 类型,所以出现了这个异常。

根据你给的有限的资料,暂时只能分析道这么多了。