Search code examples
javaemailapache-cameljakarta-mailmicrosoft-exchange

Possible to connect with a Microsoft Exchange shared mailbox via service account using JavaMail and Apache Camel Mail (IMAP)?


We are using Apache Camel to connect via IMAP to our inbox. The Apache Camel Mail components are build on JavaMail.

Our testing server is using Outlook and Office 365. We are using outlook.office365.com as the host/domain and a personal user's email account is the username and so forth with their password. This works well, considering the credentials are those of a registered personal user connecting to their individual inbox.

<from uri=imaps:outlook.office.365.com:[email protected]&password=blah/>

The production server is a shared mailbox where we have a service account set up. This service account will ideally act as the 'user' of the mailbox. There is not an 'actual user' attached to the mailbox. We are hoping to use the service account username as the 'un' field and the password for the account to gain access.

<from uri=imaps:host-domain:993?username=ServiceAccuntUN&password=ServiceAccountPW/>

Or

<from uri=imaps:[email protected]:993?username=ServiceAccuntUN&password=ServiceAccountPW/>

Or

<from uri=imaps:domain:[email protected]/ServiceAccuntUN&password=ServiceAccountPW/>

Does anybody have any experiences they would like to share using Microsoft Exchange Service Accounts to access shared mailboxes? I should not that this is a Microsoft Exchange 2010 Server.


Solution

  • For the record, connecting with the Apache Camel component works the same as the typical Exchange 2010 login.

    The username property should be: DOMAIN\SERVICE_ACCOUNT\SHARED_MAILBOX_ALIAS

    The password should be that of the service account.

    We have found JavaMail and Apache Camel Mail to be very reliable in our use case.

    (for additional info, see the comments above)