none
microsoft.exchange.webservices.data.ServiceRequestException: The request failed RRS feed

  • Question

  • I need to integrate an office 365 mail service in our Liferay Product.

    I am trying with the next main function prior to set it in the app code. When I run this piece of code the console shows that error. microsoft.exchange.webservices.data.ServiceRequestException: The request failed   

        public static void main(String[] args) {

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            ExchangeCredentials credentials = new WebCredentials("our@office365mail.com", "pass");
            
            try {
                service.setCredentials(credentials);
                service.setUrl(new URI("smtp.office365.com"));
                EmailMessage msg= new EmailMessage(service);
                msg.setSubject("Hello world!");
                msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
                msg.getToRecipients().add("mail@example.com");
                msg.send();
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

    }

    THANKS!

    Thursday, December 4, 2014 3:31 PM

All replies

  • The URL you're setting isn't right. That should be the URL for the EWS endpoint. For Office 365, you can use https://outlook.office365.com/ews/exchange.asmx there.
    Thursday, December 4, 2014 4:07 PM
    Moderator
  • Thanks Jason.

    I changed the code and added a piece:

    ...........................................

                service.setCredentials(credentials);
                service.setUseDefaultCredentials(false);
                IAutodiscoverRedirectionUrl aru = new IAutodiscoverRedirectionUrl() {
                    
                    public boolean autodiscoverRedirectionUrlValidationCallback(
                            String redirectionUrl) throws AutodiscoverLocalException {
                        
                         // The default for the validation callback is to reject the URL.
                          boolean result = false;

                          URI redirectionUri;
                        try {
                            redirectionUri = new URI(redirectionUrl);
                             // Validate the contents of the redirection URL. In this simple validation
                              // callback, the redirection URL is considered valid if it is using HTTPS
                              // to encrypt the authentication credentials.
                              if (redirectionUri.getScheme() == "https")
                              {
                                result = true;
                              }
                              
                        } catch (URISyntaxException e) {
                            e.printStackTrace();
                        }

                        return result;
                        
                    }
                };

                service.setUrl(new URI("https://outlook.office365.com/ews/exchange.asmx"));
                service.autodiscoverUrl("our@office365mail.com", aru);

    ..................................................................................

    However, in the console appears this: "The Autodiscover service couldn't be located."



    • Edited by boxgames Thursday, December 4, 2014 5:24 PM
    Thursday, December 4, 2014 5:16 PM