title: Reading a shared Outlook365 mailbox with Javamail
body: <p>My company has an outlook mailbox set up to receive data from customers each day. We have a Javamail program set up to read this Exchange mailbox and process each customers' data.</p>
  
  <p>Recently, IT moved almost all of our company mailboxes to Office365. If I change our program to look at my Office365 personal mailbox, this same Javamail program can read my email just fine. However, the mailbox being used for this data is a "shared" mailbox. If I access it over the web at <a href="https://outlook.office.com/owa/?realm=company.com" rel="nofollow noreferrer">https://outlook.office.com/owa/?realm=company.com</a>, I can click on my avatar and "Open another mailbox", and I can open this mailbox just fine without a password requested.</p>
  
  <p>My problem is that I cannot access this additional mailbox via javamail. It does not have a password, so I cannot login as (shared_mailbox)@company.com. The Microsoft page <a href="https://social.technet.microsoft.com/Forums/office/en-US/6369118f-7dee-4728-ac1c-a0c706b3d290/office-365-exchange-online-how-to-access-a-shared-mailbox-using-thunderbird-or-other-imap-client?forum=onlineservicesexchange" rel="nofollow noreferrer">https://social.technet.microsoft.com/Forums/office/en-US/6369118f-7dee-4728-ac1c-a0c706b3d290/office-365-exchange-online-how-to-access-a-shared-mailbox-using-thunderbird-or-other-imap-client?forum=onlineservicesexchange</a> suggests that I login as (my_account)@company.com\shared_mailbox. I've tried that with and without passwords, but I get "ERROR [com.tek.cb.pr.localdbimport.EmailCheckerBean] Exception caught while checking email: javax.mail.AuthenticationFailedException".</p>
  
  <p>When the program logs into outlook.office365.com, the debug messages show me</p>
  
  <pre><code>2017-03-14 15:07:44,145 INFO  [STDOUT] DEBUG: setDebug: JavaMail version 1.4ea
  2017-03-14 15:07:44,145 INFO  [STDOUT] DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
  2017-03-14 15:07:44,145 INFO  [STDOUT] DEBUG: mail.imap.fetchsize: 16384
  2017-03-14 15:07:44,145 INFO  [STDOUT] DEBUG: enable STARTTLS
  2017-03-14 15:07:44,246 INFO  [STDOUT] * OK The Microsoft Exchange IMAP4 service is ready. [TQBXAEgAUABSADIAMQBDAEEAMAAwADUANQAuAG4AYQBtAHAAcgBkADIAMQAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC]
  2017-03-14 15:07:44,246 INFO  [STDOUT] A0 CAPABILITY
  2017-03-14 15:07:44,294 INFO  [STDOUT] * CAPABILITY IMAP4 IMAP4rev1 LOGINDISABLED STARTTLS SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+^M
  A0 OK CAPABILITY completed.
  2017-03-14 15:07:44,294 INFO  [STDOUT] DEBUG: protocolConnect login, host=outlook.office365.com, user=&lt;username&gt;@&lt;company&gt;.com\&lt;shared_mailbox&gt;, password=&lt;non-null&gt;
  2017-03-14 15:07:44,294 INFO  [STDOUT] A1 STARTTLS
  2017-03-14 15:07:44,343 INFO  [STDOUT] A1 OK Begin TLS negotiation now.
  2017-03-14 15:07:44,343 INFO  [STDOUT] A2 CAPABILITY
  2017-03-14 15:07:44,607 INFO  [STDOUT] * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+^M
  A2 OK CAPABILITY completed.
  2017-03-14 15:07:44,608 INFO  [STDOUT] IMAP DEBUG: AUTH: PLAIN
  2017-03-14 15:07:44,608 INFO  [STDOUT] IMAP DEBUG: AUTH: XOAUTH2
  2017-03-14 15:07:44,608 INFO  [STDOUT] A3 AUTHENTICATE PLAIN
  2017-03-14 15:07:44,656 INFO  [STDOUT] +
  2017-03-14 15:07:44,656 INFO  [STDOUT] YmNhbHZlcnRAbmV0c2NvdXQuY29tXGNhbHZlcnQgdGVzdABiY2FsdmVydEBuZXRzY291dC5jb21cY2FsdmVydCB0ZXN0AEhvdFdhdGVyMjQ=
  2017-03-14 15:07:44,707 INFO  [STDOUT] A3 NO AUTHENTICATE failed.
  </code></pre>
  
  <p>I've also tried disabling the different types of login authentication like "plain" and "xoauth2", but I have to have STARTTLS enabled. Has anybody tried this before? I'm using IMAP because the program always has before. Should I try SMTP?</p>
  
  <p>Note that my problem is similar to this StackOverflow question, but this one deals with PHP: <a href="https://stackoverflow.com/questions/28481028/access-office356-shared-mailbox-with-php">Access Office356 shared mailbox with PHP</a></p>