Login to shared mailbox using user password through IMAP

Adrian Anghel 1 Reputation point
2022-11-25T14:40:03.213+00:00

Hi everyone,

I am creating an application that reads emails from a shared mailbox by logging in with the credentials of a user that has full delegated access to it through IMAP.
I need to send an API request to my backend with the configuration so I can read the emails. The configuration works fine when I try to connect to a user mailbox.

I do not know the shared mailbox password, only the user's. Tried using the setup described here and on Microsoft Answers, no success.

For example we have:
user mailbox: user@mathieu.company .com
user password: userpassword
shared mailbox: shared@mathieu.company .com
shared alias: SHAREDMAILBOX

Tried to do the configuration using different combinations all using userpassword, like:

IMAP SERVER: outlook.office365.com
SMTP SERVER: smtp.office365.com

The user has all mail apps enabled in M365 Admin Center and full access to the shared mailbox in Exchange Admin Center.

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,886 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,349 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Nikolaidis Athanasios 156 Reputation points
    2022-11-28T05:41:49.677+00:00

    Hi,

    You may use: user@mathieu.company .com\shared OR user@mathieu.company .onmicrosoft.com\shared & enter the password of the main user. As of October 1st, 2022, basic authentication (username and password) does not work when trying to connect to Microsoft accounts. You need to create an App Specific password when connecting to an account via IMAP
    how to create an app pwd: https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9

    But keep in mind:

    A shared mailbox is not intended for direct access. The user account for the shared mailbox should remain Disabled (or "disconnected").
    While it is technically possible, especially for applications, you must license the mailbox or use a separately licensed mailbox for shared mailbox access.
    A license is required for any user object (in this case, the user account representing the shared mailbox) that uses its own password to access a cloud resource (in this case, its own mailbox) via any protocol.
    If you use AAD Connect to synchronize the shared mailbox object, you must enable the user object in the local Active Directory, set a password, synchronize the object, and assign a license.
    Assign a license and set the password if the shared mailbox object is a cloud-only object.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  2. Aholic Liang-MSFT 13,741 Reputation points Microsoft Vendor
    2022-12-06T07:06:01.247+00:00

    Hi @Adrian Anghel ,
    You could try using the script in the following link to test user access to the sharedmailbox:
    ThisandThat/Get-IMAPAccessToken.ps1 at main · DanijelkMSFT/ThisandThat · GitHub
    If access is normal through Powershell, check if your application is using OAuth to access the shared mailbox:
    Authenticate an IMAP, POP or SMTP connection using OAuth | Microsoft Learn


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments