Search code examples
phpimap

Access Office356 shared mailbox with PHP


I'm working on a PHP script to read and parse error logs sent to a shared mailbox.

I'm using imap_open() to connect.

If I connect with the following credentials to my own mailbox, it works fine

server: {outlook.office365.com:993/imap/ssl}
username: myname@domain.com
password: mypas$word

However, if I want to connect to the sared mailbox with the follwowing credentials, I get an error

server: {outlook.office365.com:993/imap/ssl}
username: myname@domain.com\shared-folder@domain.com
password: mypas$word

The error is the following: User is authenticated but not connected. (errflg=2)

According to my research that would mean I'm using the wrong password, but since it works when connecting to my own inbox, it can't be wrong

I am a 100% certain my account can access the shared mailbox, I can access it via my account through the Office 365 webinterface

One more detail: my password includes a $ sign, but that shouldn't matter. I use single quotes on the password and escaping the $ sign doesn't help, it results in a failed login even for my personal mailbox.


Solution

  • Try using the account alias

    %USERUPN%/%SHAREDALIAS% for example:-

    user@domain.com/sharedbox where "sharedbox" is the alias of the shared mailbox instead of the full email address

    I've seen different reports of some people using forward slash ( / ) and some using a backslash ( \ )


    Edit

    Are you using the mailbox alias? Do not use sharedbox@shareddomain.com

    Exchange Configuration:

      USER EMAIL: user@maindomain.com
      PASSWORD: password
    
    
    
     SHARED MAILBOX: shared@anotherdomain.com      (could also be @domain.com, of course)
      SHARED MAILBOX ALIAS: shared-mailbox
    

    Note: Please make sure to create the UNIQUE alias always with the mailbox, because it creates the user [alias]@maindomain.com. In this case shared-mailbox@maindomain.com

    Settings for IMAP Configuration:

      EMAIL ADDRESS: shared@anotherdomain.com (shared mailbox)
      IMAP SERVER: outlook.office365.com
      SMTP SERVER: smtp.office365.com
      USERNAME: user@maindomain.com\shared-mailbox  (user\shared mailbox alias)
      PASSWORD: password (user's password)