本文介绍了microsoft.exchange.webservices.data.ServiceRequestException:请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Liferay产品中集成Office 365邮件服务。

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

我在使用应用程序代码设置之前尝试使用下一个主要功能。当我运行这段代码时,控制台会显示错误。 microsoft.exchange.webservices.data.ServiceRequestException:请求失败   


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

    public static void main(String[] args) {

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

         ExchangeCredentials凭据=新的WebCredentials(" [email protected]"," pass");

        

        尝试{

             service.setCredentials(凭据);

             service.setUrl(new URI(" smtp.office365.com"));

             EmailMessage msg = new EmailMessage(service);

             msg.setSubject(" Hello world!");

             msg.setBody(MessageBody.getMessageBodyFromText(""使用EWS Java API发送。");)
             msg.getToRecipients()。add(" [email protected]");

             msg.send();

        } catch(例外e1){

             // TODO自动生成的捕获块

             e1.printStackTrace();

        }

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        ExchangeCredentials credentials = new WebCredentials("[email protected]", "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("[email protected]");
            msg.send();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

}

感谢!

推荐答案


这篇关于microsoft.exchange.webservices.data.ServiceRequestException:请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:03