I am trying to connect to exchange web server APIs from java. I want to configure the mail flow rules. This is the code I am using –
exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
exchangeService.setUrl(new URI("https://outlook.office365.com/EWS/exchange.asmx"));
ExchangeCredentials credentials = new TokenCredentials(accessToken);
this.exchangeService.setCredentials(credentials);
exchangeService.getInboxRules();
The account I’m trying to connect to is a trial account with a domain like – <org_name>.onmicrosoft.com. The credentials are fetched from the graph API oauth flow. I am using this library – https://github.com/OfficeDev/ews-java-api/tree/master
I get a 500 error as response with this text – The request failed. An internal server error occurred. The operation failed.
Is there something wrong with my approach or some documentation I can’t seem to be able to find.
If by Mail Flow rules you mean the transport Rules eg https://learn.microsoft.com/en-us/exchange/security-and-compliance/mail-flow-rules/mail-flow-rules then EWS isn’t the correct API to use. EWS will let you modify the Inbox rules for each user (so will the Graph https://learn.microsoft.com/en-us/graph/api/mailfolder-list-messagerules?view=graph-rest-1.0&tabs=http which is a better approach if this is what you are trying to achieve). The only method of modifying the Mail Flow transport rules would be to use the exov3 cmdlets https://learn.microsoft.com/en-us/powershell/module/exchange/get-transportrule?view=exchange-ps.
Please consider to do these steps for solving your error 500
- Check your error log on log file, when the log file was available on your environtment. Do fixing as soon as you can.
- Remove your cache & cookies after you fix any issue.
- Make sure server was running or at least can receive ping from your any device