ServiceRequestException:使用Java的Microsoft Exchange Server请求失败

ServiceRequestException:使用Java的Microsoft Exchange Server请求失败,java,exchangewebservices,Java,Exchangewebservices,因此,我尝试使用ews java api发送一封hello world电子邮件 我的代码如下所示: ExchangeService exchangeWebService = new ExchangeService(ExchangeVersion.Exchange2010_SP2); exchangeWebService.setCredentials(new WebCredentials(username , password, localPcDomain)); excha

因此,我尝试使用ews java api发送一封hello world电子邮件

我的代码如下所示:

    ExchangeService exchangeWebService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
    exchangeWebService.setCredentials(new WebCredentials(username , password, localPcDomain));
    exchangeWebService.setUrl(new URI(companyExchangeURL));
    EmailMessage msg= new EmailMessage(exchangeWebService);
    msg.setSubject("Hello world!");
    msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
    msg.getToRecipients().add(testEmail);
    msg.send();
但我有以下例外:

microsoft.exchange.webservices.data.ServiceRequestException: The request failed. The request failed. sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: microsoft.exchange.webservices.data.ServiceRequestException: The request failed. sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

对我需要做什么有什么想法吗?我尝试过使用autodiscover,但它似乎总是失败。

从错误中听起来可能是SSL问题(无效证书、不受信任的证书等)。快速测试是转到该服务器的OWA url,查看浏览器是否给出有关SSL证书的警告或错误