In one of my Laravel 8 based applications, I want to switch from Mailgun to Office365 as a service change. Here is the information I have to integrate:
SMTP hostname: smtp.office365.com
Port: 587
Encryption method: STARTTLS
SSL Protocol: OFF
TLS Protocol: ON
SMTP Username: smtp_user_email
SMTP Password: smtp_password
So I write the following code in my .env file:
MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=smtp_user_email
MAIL_PASSWORD=smtp_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=smtp_user_email
MAIL_FROM_NAME="${APP_NAME}"
Then test the default Forget Password
form of Laravel (so there should be no issue related to that form as it is the standard form of Laravel). But I receive the following response:
Swift_TransportException Failed to authenticate on SMTP server with username "smtp_user_email" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 5.7.139 Authentication unsuccessful, the user credentials were incorrect. [SI2PR02CA0047.apcprd02.prod.outlook.com] ". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [SI2PR02CA0047.apcprd02.prod.outlook.com] ".
I check the username and password, which is OK but I have no idea why it returns authenticationon related error!
Does anyone why actually I missing that returns the error?
- Thanks