Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

imap - 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.comshared-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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Another solution that worked for us is to add the username data to the mailbox parameter using the appropriate flags.

For example, with the Office 365 configuration of

USER EMAIL: user@maindomain.com
PASSWORD: password
SHARED MAILBOX: shared@anotherdomain.com

then the imap_open call would be

imap_open("{outlook.office365.com:993/imap/ssl/authuser=user@maindomain.com/user=shared@anotherdomain.com}", "user@maindomain.com", "password");

Note the inclusion of the main user email using the /authuser flag and the shared mailbox using the /user flag.

That worked for us when the mailbox alias approach in the previous answer was not successful.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...