Free Support Forum - aspose.com

Error connecting to Exchange webservice (Java)

If I try to connect to an Exchange server with the following Java code:
IEWSClient client = EWSClient.getEWSClient(url, user, pw, domain);
Aspose.Email throws an exception:

Exception in thread “main” java.lang.RuntimeException: class com.aspose.email.system.exceptions.WebException: Error: 4 (Error writing headers) —> class com.aspose.email.system.exceptions.WebException: Error writing headers —> class com.aspose.email.system.exceptions.IOException: The authentication or decryption has failed. —> class com.aspose.email.system.exceptions.IOException: The authentication or decryption has failed. —> class com.aspose.email.internal.fb.za: The authentication or decryption has failed.

What causes this exception?

When I try to connect to another server, everything works as expected.

@jphhoeks,

I have observed the stack trace shared by you. It seems that the credentials you are providing are wrong for the account you are trying to access.

Ofcourse I checked the credentials. When I use the same credentials with the webmail, it is working. I tried all variations with Aspose:

user: “abc” password: “pw” domain: “adomain”
user: “adomain\abc” password: “pw” domain: “”
user: “abc@adomain.tld” password: “pw” domain: “”

Evertything fails.

Also, when I try another server and use wrong credentials, I get the following message:

Exception in thread “main” java.lang.RuntimeException: class com.aspose.email.system.exceptions.WebException: The remote server returned an error: (401) Unauthorized.
com.aspose.email.internal.o.zab.b(Unknown Source)
com.aspose.email.internal.o.zab.a(Unknown Source)
com.aspose.email.internal.o.zbh.a(Unknown Source)
com.aspose.email.internal.o.zbi.invoke(Unknown Source)
com.aspose.email.system.zd.a(Unknown Source)
com.aspose.email.internal.ex.zc.a(Unknown Source)
com.aspose.email.internal.ah.zg.run(SourceFile:66)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
at com.aspose.email.zg.a(SourceFile:250)
at com.aspose.email.zg.a(SourceFile:318)
at com.aspose.email.EWSClient.a(SourceFile:403)
at com.aspose.email.EWSClient.getEWSClient(SourceFile:351)
at com.aspose.email.EWSClient.getEWSClient(SourceFile:336)
at com.aspose.email.EWSClient.getEWSClient(SourceFile:182)
at AsposeTest.listMessagesFromInboxFolderOnExchangeServerUsingEWS(AsposeTest.java:16)
at AsposeTest.main(AsposeTest.java:11)
Caused by: class com.aspose.email.system.exceptions.WebException: The remote server returned an error: (401) Unauthorized.
com.aspose.email.internal.o.zab.b(Unknown Source)
com.aspose.email.internal.o.zab.a(Unknown Source)
com.aspose.email.internal.o.zbh.a(Unknown Source)
com.aspose.email.internal.o.zbi.invoke(Unknown Source)
com.aspose.email.system.zd.a(Unknown Source)
com.aspose.email.internal.ex.zc.a(Unknown Source)
com.aspose.email.internal.ah.zg.run(SourceFile:66)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
at com.aspose.email.internal.o.zab.b(Unknown Source)
at com.aspose.email.internal.o.zab.a(Unknown Source)
at com.aspose.email.internal.o.zbh.a(Unknown Source)
at com.aspose.email.internal.o.zbi.invoke(Unknown Source)
at com.aspose.email.system.zd.a(Unknown Source)
at com.aspose.email.internal.ex.zc.a(Unknown Source)
at com.aspose.email.internal.ah.zg.run(SourceFile:66)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

@jphhoeks,

It does not look like the problem of Aspose.Email. Can you please to check connection with MS Outlook, and then when he will have success to use the same credentials that you have given in Aspose.Email.

Also you may check following combinations:
user: “abc” password: “pw” domain: “adomain.tld”
user: “abc” password: “pw” domain: “

But first of all he has to check if web service is accessible For this you have to go to following URL:
https://hisservername/ews/exchange.asmx

Probably firewall blocks web service. You have to change HISSERVERNAME to your server’s name.