Intermittent smtp authentication errors with Laravel 8

Colin Harper 1 Reputation point
2021-11-08T10:33:17.817+00:00

We have started receiving intermittent authentication errors with Laravel. Mails are failing to send the first time and then when retrying the Horizon job, that sends the mail, it sends successfully.

Here is the error:

Failed to authenticate on SMTP server with username "<hidden>" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 250 but got code "235", with message "235 2.7.0 Authentication successful ". Authenticator XOAUTH2 returned Expected response code 250 but got code "503", with message "503 5.5.2 Auth command already specified ". {"exception":"[object] (Swift_TransportException(code: 0): Failed to authenticate on SMTP server with username \"<hidden>\" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 250 but got code \"235\", with message \"235 2.7.0 Authentication successful\r\n\". Authenticator XOAUTH2 returned Expected response code 250 but got code \"503\", with message \"503 5.5.2 Auth command already specified\r\n\". at <hidden>/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:191)"} 

Here are the .env mail settings:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_FROM_NAME="from_name"
MAIL_FROM_ADDRESS="from_address"
MAIL_USERNAME="username"
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_ATTACHMENT_WHITELIST=whitelisted_addresses

The password contains only alphanumeric characters, there are no special characters that would cause errors with it.

This is a production environment.

Exchange Exchange Server Development
Exchange Exchange Server Management
{count} votes

1 answer

Sort by: Most helpful
  1. KyleXu-MSFT 26,396 Reputation points
    2021-11-09T02:50:17.063+00:00

    @Colin Harper

    This error is generated with Laravel 8 rather than Exchange online. I would suggest you try to send email from PowerShell when this error occur, if you could send email from PowerShell, it means there doesn't exist issue with Exchange online side.

    Based on my searching, Laravel 8 requires Office 365 disable the security default configuration, here is a similar thread: Using Office 365 SMTP server
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

    For more detailed requirements, I suggest you confirm with Laravel 8. I also help you add the Exchange development to this thread.

    At the same time, I suggest that you do not send a large number of emails in a short time, otherwise your account may be temporarily banned from sending.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.