我发送邮件的代码
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("shiva@shiva.com","pwd");
service.setCredentials(credentials);
service.setUrl(new URI("C:/shiva/Services.asmx"));
EmailMessage msg = new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.getToRecipients().add("shiva@shiva.com");
msg.send();
当我运行代码
时,我遇到了以下错误microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Protocol C isn't supported for service request.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74).
.
.
.
.
Caused by: microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException: Protocol C isn't supported for service request.
at microsoft.exchange.webservices.data.core.ExchangeServiceBase.prepareHttpWebRequestForUrl(ExchangeServiceBase.java:322).
.
.
.
请帮帮我。
答案 0 :(得分:1)
问题是您没有指向您的Exchange Web服务(EWS)实例托管的URI。而只是指向文件系统中的位置:
service.setUrl(new URI("C:/shiva/Services.asmx"));
因此,URI类试图将C:/
解释为在这种情况下无法工作的协议。
您需要做的是:在Web服务器上托管您的EWS实例(在这种情况下通常是Microsoft IIS。我认为您需要一台安装了所需的Windows服务器服务器角色等)。并让您的代码指向该URI:
service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx"));