microsoft.exchange.webservices.data.ServiceRequestException:请求失败 [英] microsoft.exchange.webservices.data.ServiceRequestException: The request failed

查看:1520
本文介绍了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(" our@office365mail.com"," 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(" mail@example.com");

             msg.send();

        } catch(例外e1){

             // TODO自动生成的捕获块

             e1.printStackTrace();

        }

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();
        }

}

感谢!

推荐答案

您设置的网址不对。那应该是 EWS端点的
网址。对于Office 365,您可以使用

https://outlook.office365.com/ews/exchange.asmx
那里。
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.


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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆