title: How to fetch mails from office365 account in MVC application which uses Office365 authentication
body: <p>I am using following code for fetching emails from office 365 account in <code>MVC</code> application But it is not working, please help me in this issue.</p>
  
  <pre><code>    try
      {
             string token = Request.Params[0];
             string email = Request.Params["AUTH_USER"];
             OutlookServicesClient client = new  OutlookServicesClient(new Uri("https://outlook.office365.com/"),
                      async() =&gt;
                      {
                          return token;
                      });
      var mailResults = await client.Me.Messages
                                    .Take(10)
                              .Select(m=&gt;new{m.Subject,m.DateTimeReceived,m.From})
                              .ExecuteAsync();
  
       string content = "";
  
        foreach (var msg in mailResults.CurrentPage)
        {
            content += string.Format("Subject: {0}&lt;br/&gt;", msg.ToString());
        }
            return Content(content); 
    }
  
  catch (Exception ex)
     {
       return Content(string.Format("ERROR retrieving messages: {0}",ex.Message));
     }
  </code></pre>