0

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 "xxxxxx@companyname.co" 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
MAIL_USERNAME=xxxxxx@companyname.co
MAIL_PASSWORD=emailPassword
MAIL_ENCRYPTION=tls
MAIL_SMTPAuth=true
MAIL_FROM_NAME=CompanyName
MAIL_FROM_ADDRESS=xxxxxx@companyname.co

*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.

ecfz
  • 33
  • 3
  • 6

3 Answers3

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?

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
sohal07
  • 440
  • 8
  • 21
0

You have to enable the 2 factor authentication, the go to your account settings and create an application password. Then you have to use the new application password in your code. Check this link