Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Connect to MailBox using EWS

$
0
0

Hi,

I am trying to connect to Outlook Mail box using EWS protocol. I am using EWS managed Java API (ews-java-api-2.0.jar). This jar doesn't support the EWS Exchange 2013 version and getting the below exception when i try to run my java program. Is there any other java api version that supports EWS Exchange 2013. Can you please help with this issue.

ERROR:

"Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: The mailbox that was requested doesn't support the specified RequestServerVersion."

Below is the java code:

import java.net.URI;
import java.net.URISyntaxException;

import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.service.item.EmailMessage;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;
import microsoft.exchange.webservices.data.property.complex.MessageBody;


public class EWS {

                public static void main(String[] args) throws Exception {
                                testMethod();
                                System.out.println("mail sent.. have fun");

                }


                public static  void testMethod() throws Exception {

                        ExchangeService service = new ExchangeService();
                        ExchangeCredentials credentials = new WebCredentials("username", "password");
                        service.setCredentials(credentials);

                    try {
                        service.setUrl(new URI("https://xxxxxx/ews/exchange.asmx"));
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }

                    EmailMessage msg;
                    try {
                       msg = new EmailMessage(service);
                        msg.setSubject("hello world");
                        msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS API"));
                        msg.getToRecipients().add("myemailaddrees");
                        msg.send();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    System.out.println("Hello");
}
}


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>