title: How to read email with proper rights in token
body: <p>I am trying to upgrade an application (it should fetch emails from a mailbox every few minutes) from Microsoft EWS deprecated API to the new Graph API, but I am facing some issues.</p>
  <p>This is my class for the connector :</p>
  <pre><code>public class O365graphApiConnector {
  
    private final GraphServiceClient&lt;Request&gt; graphClient;
  
    public O365graphApiConnector(String clientId, String username, String password) {
  
      final UsernamePasswordCredential usernamePasswordCredential =
          new UsernamePasswordCredentialBuilder()
              .clientId(clientId)
              .username(username)
              .password(password)
              .build();
  
      final TokenCredentialAuthProvider tokenCredentialAuthProvider =
          new TokenCredentialAuthProvider(usernamePasswordCredential);
  
      graphClient=GraphServiceClient.builder()
          .authenticationProvider(tokenCredentialAuthProvider)
          .buildClient();
    }
  
    public User getUserProfile() {
      return graphClient.me().buildRequest().get();
    }
  
    public MessageCollectionPage getOutlookEmails() {
      return graphClient.me().messages().buildRequest().get();
    }
  
  }
  </code></pre>
  <p>I am using <code>com.azure:azure-identity:1.4.2</code> and <code>com.microsoft.graph:microsoft-graph:5.8.0</code>.</p>
  <p>I build the connector, passing the <code>clientId</code>, <code>username</code> and <code>password</code>. I am able to call <code>getUserProfile</code> , and I am getting something, so the authentication &quot;works&quot;.</p>
  <p>However, I get a 404 when calling <code>getOutlookEmails</code> :</p>
  <blockquote>
  <p>SEVERE: Throwable detail:
  com.microsoft.graph.http.GraphServiceException: Error code:
  ResourceNotFound Error message: Resource could not be discovered.</p>
  <p>GET <a href="https://graph.microsoft.com/v1.0/me/messages" rel="nofollow noreferrer">https://graph.microsoft.com/v1.0/me/messages</a> SdkVersion :
  graph-java/v5.8.0</p>
  <p>404 : Not Found [...]</p>
  </blockquote>
  <p>When I run this in debug mode and intercept the token, it seems to be OK though : I have a bunch of rights that my admin has given to the applicative account :</p>
  <pre><code> &quot;scp&quot;: &quot;EWS.AccessAsUser.All Mail.Read Mail.Read.Shared Mail.ReadBasic Mail.ReadWrite
   Mail.ReadWrite.Shared Mail.Send Mail.Send.Shared MailboxSettings.ReadWrite User.Read User.Read.All User.ReadWrite profile openid email&quot;
  </code></pre>
  <p>This is part of what we see on the admin side (more rights were added after the screenshot was taken) :</p>
  <p><a href="https://i.stack.imgur.com/zKi2v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zKi2v.png" alt="enter image description here" /></a></p>
  <p>My understanding is that this should be enough to get access to the emails of the given mailbox programmatically, but apparently, it's not.</p>
  <p>Any idea of what I am missing ?</p>