CM_DEV
CM_DEV

Reputation: 63

401 error when trying to connect to office 365 with EWS

I am having a problem accessing a mailbox on Office 365 through an Azure worker role application using EWS Managed API 2.2. This is the error message that I get:

The request failed. The remote server returned an error: (401) Unauthorized.

It works when using my mailbox, which is also on Office 365, but not when I try to connect to another that is to be used for this application. Both mailboxes are set up as part of the same corporate account in Office 365, but the domain for mine is [company].com, while the one that doesn't work is [company].net. EWS has been activated for both addresses. I can log in in to Outlook Web Access with the other account with no problems, so the login credentials are working. The strange thing is, it used to work about 2 months ago when I originally built the application and was testing. I hadn't tried to use it since then until yesterday, when I was testing it before deploying to production.

Are there any other settings that I can check that would prevent EWS from working for the other mailbox?

Upvotes: 0

Views: 10148

Answers (3)

Jason Johnston
Jason Johnston

Reputation: 17702

I would probably try your code from your desktop, to see if maybe it's something about running in an Azure worker app. I'd also enable tracing and see what kind of authorization headers are being sent. It should be using Basic auth. Are you explicitly setting the username/password in your code?

Upvotes: 0

Dhananjay Kashyap
Dhananjay Kashyap

Reputation: 621

I added following JAR file and it got resolved all dependency.

EWSJavaAPI_1.2original.jar, 
EWSJavaAPIWithJars_1.2.1.jar, 
httpclient-4.2.5.jar, 
httpcore-4.2.4.jar, 
jcifs-1.3.17.jar, 
commons-codec-1.7.jar, 
commons-logging-1.1.1.jar

You need to open the URL in chrome browser - https://outlook.office365.com/EWS/Exchange.asmx Then enter UserName and Password of your authenticating credentials which you are going to use in your code.

Upvotes: 0

CM_DEV
CM_DEV

Reputation: 63

It turned out to be an incorrectly typed password for the account in the config file.

Upvotes: 1

Related Questions