Search code examples
laravelauthenticationubuntuoffice365smtp-auth

Failed to authenticate on SMTP server when using office 365 e-mail with Laravel on ubuntu with lemp stack on digitalocean


I have setup a Laravel application on an Ubuntu droplet at DigitalOcean. Now I'm trying to send out e-mails using an office 365 mail account. However I get the following error:

  Failed to authenticate on SMTP server with username "[email protected]" using the following
  authenticators: "LOGIN", "XOAUTH2". Authenticator "LOGIN" returned "Expected response code 
  "235" but got code "535", with message "535 5.7.139 Authentication unsuccessful, 
  SmtpClientAuthentication is disabled for the Mailbox. Visit 
  https://aka.ms/smtp_auth_disabled for more information. 
  [AS4P192CA0012.EURP192.PROD.OUTLOOK.COM 2023-05-22T18:20:29.187Z 08DB5A  1254806496]".". 
  Authenticator "XOAUTH2" returned "Expected response code "235" but got code "535", with 
  message "535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for 
  the Mailbox. Visit https://aka.ms/smtp_auth_disabled for more information. 
  [AS4P192CA0012.EURP192.PROD.OUTLOOK.COM 2023-05-22T18:20:39.951Z 08DB5A1254806496]".".

I'm using the following configuration in the .env file:

MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME="[email protected]"
MAIL_PASSWORD=***PASSWORD***
MAIL_ENCRYPTION=STARTTLS
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

I read that I could enable/disable SMTP auth (https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission). I guess that is the setting as in the screenshot below. I tried with the checkbox both checked and unchecked, but it makes no difference.

enter image description here

So the question is: what am I missing to get smpt working on my website?


Solution

  • The error message gives the suggestion to visit this page: https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission. So I tried with Authenticated SMTP checked and unchecked and saw no change.

    Finally I found out from here: https://mkerala.com/solution-535-5-7-3-authentication-unsuccessful-office-365-smtp-error/ that it takes a while for the setting to take effect. In my case about 20 minutes.