'Sending Email using Outlook / Office365 with Laravel - Failed to authenticate on SMTP server

I'm trying to send an email with our Laravel app using Office365/Outlook. It has worked well with gmail but when I switched over to Office365, the following error appears:

Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [HKAPR03CA0035.apcprd03.prod.outlook.com] ". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [HKAPR03CA0035.apcprd03.prod.outlook.com] ".

This is what I have in my .env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=emailPassword
MAIL_ENCRYPTION=tls
MAIL_SMTPAuth=true
MAIL_FROM_NAME=CompanyName
[email protected]

*note: this is not the real username, password and from address.

I also tried changing the port to 25 but I get the same error

I'm using a dedicated support email from my company. And from what I confirmed with our IT, the support email does not have 2 factor authentication and the "Authenticated SMTP" setting is also enabled via the admin panel of Office365 so I don't know what seems to be the problem.



Solution 1:[1]

Keep in mind that for the new tenants, Microsoft turns SMTP authentication off, and it needs to be explicitly enabled. Please see Enable or disable authenticated client SMTP submission (SMTP AUTH) in Exchange Online as well as What are security defaults?

Solution 2:[2]

I had the same issue and I called Microsoft support. They instructed me to change some security properties in Microsoft Azure. Here is my answer.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Dharman