当我尝试使用 Exchange Web 服务将邮件发送到 Exchange Server 时请求失败
Request failing when I try to send mail to Exchange Server using Exchange Web Services
我发送邮件的代码
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).
.
.
.
请帮帮我
问题是您没有指向您的 Exchange Web 服务 (EWS) 实例所在的 URI 托管。相反,您只是指向文件系统中的位置:
service.setUrl(new URI("C:/shiva/Services.asmx"));
所以 URI-class 试图将 C:/
解释为在这种情况下不起作用的协议。
您需要执行以下操作:将您的 EWS 实例托管在网络服务器上(在这种情况下通常是 Microsoft IIS。我认为您需要一个 Windows 服务器并设置好所需的服务器角色等)。并让您的代码指向该 URI:
service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx"));
我发送邮件的代码
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).
.
.
.
请帮帮我
问题是您没有指向您的 Exchange Web 服务 (EWS) 实例所在的 URI 托管。相反,您只是指向文件系统中的位置:
service.setUrl(new URI("C:/shiva/Services.asmx"));
所以 URI-class 试图将 C:/
解释为在这种情况下不起作用的协议。
您需要执行以下操作:将您的 EWS 实例托管在网络服务器上(在这种情况下通常是 Microsoft IIS。我认为您需要一个 Windows 服务器并设置好所需的服务器角色等)。并让您的代码指向该 URI:
service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx"));