Failed to authenticate on SMTP server with username in smtp.office365.com

Viewed 9514

In my Laravel-5.8 project I am trying to send email/notification using office365

config/mail.php

<?php

  return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.office365.com'),

    'port' => env('MAIL_PORT', 587),

    'from' => [

        'address' => env('MAIL_FROM_ADDRESS', 'testingemail@mycompany.com'),
        'name' => env('MAIL_FROM_NAME', 'JJJ'),
    ],


    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME','testing@mycompany.com'),

    'password' => env('MAIL_PASSWORD','testing'),


    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

    'log_channel' => env('MAIL_LOG_CHANNEL'),

];

But I got this error:

#message: """ Failed to authenticate on SMTP server with username "testing@mycompany.com" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [LO2P265CA0268.GBRP265.PROD.OUTLOOK.COM] ◀ ". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [LO2P265CA0268.GBRP265.PROD.OUTLOOK.COM] ◀ ". """

How do I resolve it?

Thanks

2 Answers

please write this code in env file

use your smtp mail instead of smtp.office365.com

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=testing@mycompany.com
MAIL_PASSWORD=testing
MAIL_ENCRYPTION=tls

then run command

php artisan config:cache

I had the same issue, tried all the suggestions on google before finally having to call Microsoft Support. The operator got me to change some security properties in the Microsoft Azure Active Directory at portal.azure.com

And here's my .env variables:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=tls

Please see the screenshot for instructions.

enter image description here

Related