Siva R
Siva R

Reputation: 447

Request failing when I try to send mail to Exchange Server using Exchange Web Services

My code to send mail

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("[email protected]","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("[email protected]");
msg.send();

I'm getting following error when I ran above code

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).
.
.
.

Please help me.

Upvotes: 0

Views: 1225

Answers (1)

Jan Köhler
Jan Köhler

Reputation: 6030

The problem is that you don't point to the URI where your Exchange Web Services (EWS) instance is hosted. Instead your just pointing to the location in the file-system:

service.setUrl(new URI("C:/shiva/Services.asmx"));

So the URI-class tries to interpret C:/ as a protocol which won't work in this situation.

What you'll have to do is the following: Host your EWS-instance on a web server (usually Microsoft IIS in this case. I think you'll need a Windows Server with having set up the required server roles etc.). And let your code point to that URI instead:

service.setUrl(new URI("http://localhost:1234/someWhere/Services.asmx"));

Upvotes: 1

Related Questions