barbushin/php-imap

ConnectionException "LOGIN failed." with office 365 since Microsoft activated two factor auth

Opened this issue · 2 comments

Environment (please complete the following information):

  • PHP IMAP version: 5.0.1
  • PHP Version: 7.4.26
  • Type of execution: wamp local on windows, and apache server

I had this lib working since years ago, but microsoft decided add two factor auth to office 365 accounts, and it broked my connection. I get "LOGIN failed." error when I try to connect:

$server = "{outlook.office365.com:993/imap/ssl}INBOX";
//$server = "{outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX";

$mbox_connection = new PhpImap\Mailbox($server, $email, $password, __DIR__ . '/files/');

try {
    $mailsIds = $mbox_connection->searchMailbox('ALL');
} catch(\Exception $ex) {
    die("<pre>".print_r($ex, true)."</pre>");
}

I had test this two $server address, and many others.

Email is my office 365 account, and password I tested my connection account password, and other password generated in the my account office 365 web:
My account / Security Info / Add sign-in method / App password
In adition, I had activated two factor auth for this account.

I get a ConnectionException:

PhpImap\Exceptions\ConnectionException Object
(
[message:protected] => ["LOGIN failed."]
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => C:\wamp64\www\test-imap\vendor\php-imap\php-imap\src\PhpImap\Imap.php
[line:protected] => 712
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\wamp64\www\test-imap\vendor\php-imap\php-imap\src\PhpImap\Mailbox.php
[line] => 1725
[function] => open
[class] => PhpImap\Imap
[type] => ::
[args] => Array
(
[0] => {outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX
[1] => [EMAIL]
[2] => [PASSWORD]
[3] => 0
[4] => 0
[5] => Array
(
)

                    )

            )

        [1] => Array
            (
                [file] => C:\wamp64\www\test-imap\vendor\php-imap\php-imap\src\PhpImap\Mailbox.php
                [line] => 1686
                [function] => initImapStream
                [class] => PhpImap\Mailbox
                [type] => ->
                [args] => Array
                    (
                    )

            )

        [2] => Array
            (
                [file] => C:\wamp64\www\test-imap\vendor\php-imap\php-imap\src\PhpImap\Mailbox.php
                [line] => 469
                [function] => initImapStreamWithRetry
                [class] => PhpImap\Mailbox
                [type] => ->
                [args] => Array
                    (
                    )

            )

        [3] => Array
            (
                [file] => C:\wamp64\www\test-imap\vendor\php-imap\php-imap\src\PhpImap\Mailbox.php
                [line] => 664
                [function] => getImapStream
                [class] => PhpImap\Mailbox
                [type] => ->
                [args] => Array
                    (
                    )

            )

        [4] => Array
            (
                [file] => C:\wamp64\www\test-imap\index.php
                [line] => 36
                [function] => searchMailbox
                [class] => PhpImap\Mailbox
                [type] => ->
                [args] => Array
                    (
                        [0] => ALL
                    )

            )

    )

[previous:Exception:private] => 
[xdebug_message] => ( ! ) PhpImap\Exceptions\ConnectionException: ["LOGIN failed."] in C:\wamp64\www\test-imap\vendor\php-imap\php-imap\src\PhpImap\Imap.php on line 712

Call Stack
#TimeMemoryFunctionLocation
10.0005365632{main}( )...\index.php:0
20.0009368968PhpImap\Mailbox->searchMailbox( $criteria = 'ALL', $disableServerEncoding = ??? )...\index.php:36
30.0009368968PhpImap\Mailbox->getImapStream( $forceConnection = ??? )...\Mailbox.php:664
40.0009368968PhpImap\Mailbox->initImapStreamWithRetry( )...\Mailbox.php:469

)

@miguelangelss4 be careful, i think you just leaked your email address and your password in the exception that you copied, in the [args] section.

You can edit your issue it to censor/remove the information.

@MrMitch thanks a lot!