[英]401 Unauthorized when trying to send emails from EWS Managed API
Ok so I am developing an addin which must automatically send emails to others. 好的,所以我正在开发一个插件,该插件必须自动向他人发送电子邮件。 I know that office-js does not have permissions to do so and I have started using EWS Managed API.
我知道office-js无权这样做,并且我已经开始使用EWS托管API。 I have implemented SSO token and I get it with:
我已经实现了SSO令牌,并获得了:
Office.context.auth.getAccessTokenAsync()
After I get the token I make a request call to my server where I have my EWS Managed API and try to send an email with the folowing code: 获得令牌后,我将向拥有我的EWS托管API的服务器发出请求,并尝试发送包含以下代码的电子邮件:
ExchangeService exService = new ExchangeService();
exService.Url = new Uri(ewsUrl);
ExchangeCredentials credentials = new OAuthCredentials(ssoToken);
exService.Credentials = credentials;
EmailMessage emailMessage = new EmailMessage(exService);
When I call emailMessage.SendAndSaveCopy();
当我致电
emailMessage.SendAndSaveCopy();
it throws 401 Error. 它会引发401错误。
If I do use WebCredentials(user, pass)
instead of OAuthCredentials(ssoToken)
it does work. 如果我确实使用
WebCredentials(user, pass)
而不是OAuthCredentials(ssoToken)
它确实可以工作。 I do not understand why (I also have set permissions on Azure Portal) 我不明白为什么(我在Azure Portal上也设置了权限)
The SSO (Single Sign on) app that you had to create, needed to be created through https://apps.dev.microsoft.com . 您必须通过https://apps.dev.microsoft.com创建必须创建的SSO(单点登录)应用程序。 This was where you create the converged apps - which allows the consented parties to sign-in with their Outlook.com accounts or the organizational accounts (which is the newer way).
在此创建融合的应用程序-允许被许可方使用其Outlook.com帐户或组织帐户(较新的方式)登录。
However EWS is not using this. 但是EWS没有使用它。 EWS is using the authentication method of older way of creating apps, which is what you need to do through Azure Portal - through AAD App registrations.
EWS使用的是较早的创建应用程序的身份验证方法,这是您需要通过Azure门户-通过AAD应用程序注册进行的操作。 More documentation on authentication of EWS here: https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/authentication-and-ews-in-exchange
有关EWS身份验证的更多文档,请访问: https : //docs.microsoft.com/zh-cn/exchange/client-developer/exchange-web-services/authentication-and-ews-in-exchange
So basically, the OAuth access token which you've retrieved can be used to query Microsoft Graph (as an example) but you can't use that to call EWS. 因此,基本上,您检索到的OAuth访问令牌可用于查询Microsoft Graph(作为示例),但是您不能使用它来调用EWS。
One very significant difference this creates is EWS is (as the name suggests, Exchange Web Services) is organizational accounts only. EWS产生的一个非常重要的区别是EWS(顾名思义,Exchange Web Services)仅是组织帐户。 You can't use that API for the Outlook.com users.
您不能为Outlook.com用户使用该API。
makeEwsRequestAsync
method. makeEwsRequestAsync
方法。 This will require you to write SOAP in javascript but it works. 您还必须将ExchangeServer.ImpersonatedUserId
属性设置为代表您发送的用户的地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.