3

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

mikefolu
  • 1,203
  • 6
  • 24
  • 57
  • I suggest you to check with your smtp with [tag:MailTrap] – STA Aug 25 '20 at 13:12
  • @sta - I am not using mailtrap. As stated in the question., I am using smtp.office365.com – mikefolu Aug 25 '20 at 13:24
  • 1
    !!!! THIS IS SOLUTION !!!!!! mods keep delete my way how so solve this : Open the Microsoft 365 admin center and go to Users > Active users. Select the user, and in the flyout that appears, click Mail. In the Email apps section, click Manage email apps. Verify the Authenticated SMTP setting: unchecked = disabled, checked = enabled. When you're finished, click Save changes. – user956584 Sep 27 '20 at 11:02

3 Answers3

2

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
sohal07
  • 440
  • 8
  • 21
  • What worked for me is setting Azure's security defaults to no, As described in the attached screenshot in this answer. To do that, please go to Azure portal > Azure Active Directory > Properties then Manage Security defaults link at the bottom, there will be a drop-down instead of Yes/No toggle, select the Conditional Access option here and all done. – Ravi Misra Mar 15 '23 at 02:06
1

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
VIKAS KATARIYA
  • 5,867
  • 3
  • 17
  • 34
  • 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] ◀ ". """ – mikefolu Aug 25 '20 at 13:58
  • Same error we are getting from above code. provide solution in detail. – Ronak Chauhan Jun 10 '22 at 06:08
-2

In your .env file, use SendMail instead of smtp

ex:

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