title: Login with domain/user/account not working with imap on exchange server using javamail
body: <p>I'm trying to connect to an exchange mailserver (not sure what version) using javamail.<br>
  I have the username and password of an account that can impersonate all other users.<br>
  I'm trying to open the store of one of the users. (password unknown)</p>
  
  <p>I did find this question <a href="https://stackoverflow.com/questions/11719205/how-to-use-javamail-for-accessing-additional-mailboxes-imap-exchange-2010">How to use Javamail for accessing additional mailboxes (IMAP, Exchange 2010)</a>. It's using [domain]/[user]/[sharedaccount] as login.</p>
  
  <p>The connection is made if I only use [domain]/[user], but with the name of the second account behind it [domain]/[user]/[impersonatedaccount] it won't work.<br>
  If I use the same credentials in Thunderbird it does make the connection.</p>
  
  <p><strong>Example:</strong><br>
  domain: abc<br>
  known username with password: admin<br>
  mailbox to connect to: wverleur@abc.com (logs in with wverleur)<br>
  Working:<br>
  abc/admin<br>
  not working:<br>
  abc/admin/wverleur</p>
  
  <p><strong><code>credentials</code> contains the following:</strong><br>
  rootUrl: mailserver.abc.com<br>
  username: admin<br>
  password: password<br>
  domain: abc<br>
  impersonation: wverleur<br>
  getImapUsername() returns domain/username/impersonation</p>
  
  <p><strong>My connection code:</strong></p>
  
  <pre><code>private void login() throws MessagingException {
      // connection properties
      Properties properties = new Properties();
  
      // TLS &amp; SSL
      properties.setProperty("mail.imaps.starttls.enable", "true");
      properties.setProperty("mail.imaps.ssl.enable", "true");
      properties.setProperty("mail.imaps.ssl.trust", credentials.getRootUrl()); // self signed certificate
  
      // login settings
      properties.setProperty("mail.imaps.auth.ntlm.disable", "true");
      properties.setProperty("mail.imaps.auth.plain.disable", "true");
      properties.setProperty("mail.imaps.auth.gssapi.disable", "true");
  
  
      // retrieve a session
      session = Session.getInstance(properties);
  
      // retrieve and open a store
      store = session.getStore("imap");
  
  
      try {
          store.connect(credentials.getRootUrl(), credentials.getImapUsername(), credentials.getPassword());
      } catch (MessagingException messagingException) {
          throw new MessagingException("Error in storeConnect: " + store.toString(),
                  messagingException);
      }
  }
  </code></pre>
  
  <p><strong>Javamail Debug shows the following:</strong><br>
  <code>DEBUG IMAP: protocolConnect login, host=[rooturl], user=[domain]\[user]\[impersonate], password=&lt;non-null&gt;</code></p>
  
  <p>Am I missing something?<br>
  Is it even possible at all?  </p>