无法使用 smtp 中的用户名在 SMTP 服务器上进行身份验证。office365.com

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

在我的 Laravel-5.8 项目中,我尝试使用 office365

发送 email/notification

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'),

];

但是我得到了这个错误:

#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] ◀ ". """

如何解决?

谢谢

请将此代码写入环境文件

使用您的 smtp 邮件而不是 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

然后运行命令

php artisan config:cache

我遇到了同样的问题,尝试了 google 上的所有建议,最后不得不致电 Microsoft 支持部门。操作员让我在 portal.azure.com

更改 Microsoft Azure Active Directory 中的一些安全属性

这是我的 .env 变量:

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

请查看屏幕截图以获取说明。