EWS Java api抛出“请求失败。请求失败。远程服务器返回错误:(401)未经授权”

时间:2019-07-17 05:54:55

标签: java office365 exchange-server office365api

当前正在使用JAVA EWS-API 2.0版本并获得401未经授权的异常。

我当前正在使用WebCredentials和TokenCredentials,在两种情况下我都遇到以下异常:

"The request failed. The request failed. The remote server returned an error: (401)Unauthorized"
 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

        ExchangeCredentials credentials = new WebCredentials("XXX@domail.com",password;

        service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx" ));

        service.setCredentials(credentials);

        EmailMessage msg= new EmailMessage(service);

        msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
        msg.setSubject("Hello world!");
        msg.getToRecipients().add( new EmailAddress( "xxx@com" ) );
        msg.send();

0 个答案:

没有答案