使用EWS检索电子邮件的邮件应用程序 - 访问被拒绝错误? [英] Mail App using EWS to retrieve email message - Access Denied error?

查看:103
本文介绍了使用EWS检索电子邮件的邮件应用程序 - 访问被拒绝错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用EWS检索当前电子邮件项主体的邮件应用程序。


在我的Javascript代码中,我正在调用Office.context.mailbox .getCallbackTokenAsync将回调标记传递给我的服务器(ASP.NET网站)。  除了令牌,我还传递了当前电子邮件的ItemId和EwsUrl。  服务器
然后获取Token,ItemId和Url并连接到EWS以检索电子邮件的正文(调用Item.Bind)。


这完美适用于我试用我的应用程序的第一封电子邮件。  如果用户点击其收件箱中的其他电子邮件,请再次打开Outlook应用,然后点击相同的"获取电子邮件"。在应用程序中的按钮,对服务器
上的Item.Bind的调用有时会导致"访问被拒绝"。检查凭据,然后重试"错误。 


我无法弄清楚为什么这会在第一次运行但在后续尝试时失败。  但它似乎与从getCallbackTokenAsync返回的令牌有关。  我尝试记录发送到我的服务器的
的每个itemIds和Tokens,我注意到每当我获得Access Denied时,发送的令牌与先前请求发送的令牌完全相同。  每当它通过一个全新的非重复令牌发送时,请求总是成功。 


  1. getCallbackTokenAsync返回的令牌是否与特定的itemId相关联?  有效令牌只能用于一个特定的ItemId吗?  (我怀疑这是真的,但我不确定)
  2. 如果是这样,那么当我切换到Outlook中的新电子邮件时,不应该每次调用getCallbackTokenAsync都会返回一个新的唯一标记吗?  (似乎  getCallbackTokenAsync已损坏,并且每次调用时都不返回
    新标记值

对于refernece,我使用的是Office365和Outlook 15.0.4701.1002


任何帮助将不胜感激。  


-Erik

解决方案

Erik,


>>从getCallbackTokenAsync返回的令牌是否与特定的itemId绑定? 有效令牌只能用于一个特定的ItemId吗?  (我怀疑这是真的,但我不确定)


根据我的测试结果,是的,该令牌只能用于特定项目。


>>如果是这样,那么当我在Outlook中切换到新的电子邮件时,不应该每次调用getCallbackTokenAsync返回一个新的唯一令牌吗?


我没有找到要描述的文档。以下是我方的测试结果。


 如果令牌未用于拨打EWS,则会在下一项中重复使用,令牌将是如果再次调用getCallbackTokenAsync,则相同。我的猜测是getCallbackTokenAsync方法不仅获取令牌,还声明在服务器端访问哪个项目
。如果您使用令牌进行EWS呼叫,那么您将获得一个不同的令牌来访问另一个项目。


希望它会有所帮助。


问候,


Jeffrey


Hi, I have a mail app that is using EWS to retrieve the body of the current email item.

In my Javascript code I am calling Office.context.mailbox.getCallbackTokenAsync to get the callback token to pass to my server (an ASP.NET website).  Along with the token I am also passing the current email's ItemId and the EwsUrl.  The server then takes the Token, ItemId, and Url and connects to EWS to retrieve the body of the email (calling Item.Bind).

This works perfectly on the first email that I try my app on.  If the user then clicks to a different email in their inbox, opens the outlook app again and then clicks the same "get email" button in the app, the call to Item.Bind on the server will occasionally result in an "Access is denied. Check credentials and try again" error. 

I can't figure out why this would work the first time but fail on subsequent tries.  But it seems to have something to do with the tokens that are being returned from getCallbackTokenAsync.  I tried logging each of the itemIds and Tokens that get sent to my server, and I noticed that whenever I get Access Denied, the token sent over is the exact same token that was sent on the previous request.  Whenever it sends over a brand new non-repeating token, the request always succeeds. 

  1. Are the tokens returned from getCallbackTokenAsync tied to a specific itemId?  Can a valid token only be used for one specific ItemId?  (I suspect this is true but I'm not sure)
  2. And if so, then shouldn't each call to getCallbackTokenAsync return a new unique token when I switch to a new email in Outlook?  (It appears as though getCallbackTokenAsync is broken and not returning new token values each time it's called)

For refernece, I'm using Office365 and Outlook version 15.0.4701.1002

Any help would be appreciated.  

-Erik

解决方案

Hi Erik,

>> Are the tokens returned from getCallbackTokenAsync tied to a specific itemId?  Can a valid token only be used for one specific ItemId?  (I suspect this is true but I'm not sure)

According to my test result, yes, the token could be only used to a specific item.

>> And if so, then shouldn't each call to getCallbackTokenAsync return a new unique token when I switch to a new email in Outlook?

I did not find to document to describe that. Here is the test result from my side.

 If the token was not used to make the EWS call, it will be re-used in the next item, the token will be the same if you call getCallbackTokenAsync again. My guess is the getCallbackTokenAsync method not just gets token but also declares which item to be accessed on the server side. If you used the token to make a EWS call, then you will get a different token to access another item.

Hope it will help.

Regards,

Jeffrey


这篇关于使用EWS检索电子邮件的邮件应用程序 - 访问被拒绝错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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