android使用微软EWS发送邮件
通常我们在android使用javamail发送邮件,可是很多时候我们需要连接Exchange服务(很多公司内部邮件服务器采用,并且未开通smtp服务)来发送邮件,这时候我们就要用到微软的 ews-java-api。官方github的地址是:https://github.com/OfficeDev/ews-java-api。然后再android studio里面按照给出的方法添加2.0依赖、build。这时候问题来了编译通过不了报错
内容如下:
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.protocol.HttpClientContext" on path: DexPathList[[zip file "/data/app/domain.test.android.jasonyu.myfirstapp-2/base.apk"],nativeLibraryDirectories=[/data/app/domain.test.android.jasonyu.myfirstapp-2/lib/x86, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at microsoft.exchange.webservices.data.core.ExchangeServiceBase.initializeHttpContext(ExchangeServiceBase.java:261) at microsoft.exchange.webservices.data.core.ExchangeServiceBase.setUseDefaultCredentials(ExchangeServiceBase.java:677) at microsoft.exchange.webservices.data.core.ExchangeServiceBase.<init>(ExchangeServiceBase.java:173) at microsoft.exchange.webservices.data.core.ExchangeService.<init>(ExchangeService.java:3718) at domain.test.android.jasonyu.myfirstapp.MainActivity.onButtonGoClick(MainActivity.java:94)
后来找到可能原因是这个api是针对java web如果想用到android端需要使用另外一个android封装:https://github.com/alipov/ews-android-api。
通过git编译 ews-android-api.jar。然后再项目中添加依赖:
compile files('libs/ews-android-api.jar')
compile 'joda-time:joda-time:2.8'
ok大功告成。