Pass credentials or token from mail app to webserver to use with EWS Managed API ExchangeService class RRS feed

  • Question

  • I would like to use the Microsoft.Exchange.WebServices.Data.ExchangeService object on the webserver that hosts my mail app.

    Can I authorize using some kind of token or something else passed from the client mail app to ExchangeService  object on the webserver without the need to ask a user interaction to enter credentials?

    Kind regards,

    • Edited by voilbak Tuesday, August 6, 2013 11:41 AM
    Tuesday, August 6, 2013 11:40 AM

All replies

  • anybody?
    Tuesday, September 3, 2013 7:54 AM
  • Hi,

    You can use Mailbox.getCallbackTokenAsync . You can use this token to authenticate against Exchange.

    Have a look at the article below. Please note, above call is only valid from OWA for now.

    For sample, look in to the code Modal of GetAttachement sample:

    [If this helps, please mark it as answer.]


    Saturday, September 14, 2013 10:16 AM
  • I get the token in OWA.

    I pass it to the webserver where I run this code

    var service = new ExchangeService(ExchangeVersion.Exchange2013)
                                      Credentials = new OAuthCredentials(token),
                                      Url =
                                          new Uri(
                var message = new EmailMessage(service);
                message.Subject = "MySubject";
                message.Body = new MessageBody("MyBody");

    I get this exception : 

    ((Microsoft.Exchange.WebServices.Data.ServiceResponseException)(e)).Message "The requested web method is unavailable to this caller or application."


    Monday, September 16, 2013 9:33 AM
  • Hi,

    Try using the value provided by EWSUrl property of Mailbox to make EWS request rather than hardcoding the EWS url.

    • Edited by Pallav Sharma Monday, September 16, 2013 3:33 PM little addition to text
    Monday, September 16, 2013 3:32 PM
  • I did,

    the url mentioned above was the url i got from the EWSUrl property.

    So the problem remains "The requested web method is unavailable to this caller or application."
    • Edited by voilbak Monday, September 16, 2013 3:41 PM
    Monday, September 16, 2013 3:41 PM
  • Hi Voilbak,

    I am doing a quick test on this and will get back to you. Meanwhile i would suggest you to enable the EWS tracing in the code and share the Request and Response SOAP.

    Thursday, September 19, 2013 5:18 AM
  • Request :

    <Trace Tag="EwsRequest" Tid="6" Time="2013-09-19 13:39:48Z" Version="15.00.0516.014">
      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:xsi="" xmlns:m="" xmlns:t="" xmlns:soap="">
          <t:RequestServerVersion Version="Exchange2013" />
          <m:CreateItem MessageDisposition="SendAndSaveCopy">
              <t:DistinguishedFolderId Id="sentitems" />
                <t:Body BodyType="HTML">MyBody</t:Body>

    Response :

    <Trace Tag="EwsResponse" Tid="6" Time="2013-09-19 13:39:59Z" Version="15.00.0516.014">
      <?xml version="1.0" encoding="utf-8"?>
      <s:Envelope xmlns:s="">
            <faultcode xmlns:a="">a:ErrorAccessDenied</faultcode>
            <faultstring xml:lang="en-US">The requested web method is unavailable to this caller or application.</faultstring>
              <e:ResponseCode xmlns:e="">ErrorAccessDenied</e:ResponseCode>
              <e:Message xmlns:e="">The requested web method is unavailable to this caller or application.</e:Message>

    I can also send you my test project if you want.

    Thursday, September 19, 2013 1:43 PM
  • Hi,

    Have a look at the Forum post below, which provides details on using OAuth with Exchange 2013.

    Tuesday, September 24, 2013 5:26 AM
  • Hi,

    I have read the thread above carefully.

    This explains how to get a token using my mail app id and GetClientAccesToken.

    I don't think this contains a solution for my problem because as Glen Scales states : 

    "Why are trying to use GetClientAccessToken ?? this is used to generate a Token that you can use with in either Exchange, SharePoint or Link based on the credentials your using, hence you would always need credentials to call it.

    If you have Token from SharePoint already you don't need to call this just use the Token you already have via the OAuthCredentials Class."

    Tuesday, September 24, 2013 7:54 AM
  • The token you got is just for authentication not authorization. Currently, mail app support client side JavaScript call EWS Webservices. Please see refered page for detail:

    Wednesday, February 19, 2014 5:42 AM