Share via

Failed to authenticate on smtp server outlook in laravel.

Yosua Ferdian 11 Reputation points
2021-09-08T09:59:58.643+00:00

There's any way to authenticate in to outlook account with OTP code protection for SMTP use in laravel?
i am trying with setting:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=(username)
MAIL_PASSWORD=(password)
MAIL_ENCRYPTION=tls
MAIL_FROM=(email/username)

and i got error= Failed to authenticate on SMTP server with username "(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 request did not meet the criteria to be authenticated successfully. Contact your administrator. [SG2PR03CA0140.apcprd03.prod.outlook.com]
". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [SG2PR03CA0140.apcprd03.prod.outlook.com]
".

Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

Outlook | Windows | Classic Outlook for Windows | For business

2 answers

Sort by: Most helpful
  1. Taz 9,366 Reputation points MVP Volunteer Moderator
    2021-09-08T11:43:19.3+00:00

    Hello @Yosua Ferdian !

    Hope you are having a great day!

    Can you try changing the "MAIL_DRIVER=smtp" to “MAIL_DRIVER=SendMail” and use the Office 365 TLS settings.

    Let me know if the above solution solves your issue. I will be glad to help you!

    Thank you,
    Tasadduq


    | Please don't forget to Upvote and Accept as answer if the reply is helpful |

    Was this answer helpful?

    2 people found this answer helpful.

  2. Joyce Shen - MSFT 16,706 Reputation points
    2021-09-09T02:47:09.423+00:00

    Hi @Yosua Ferdian

    According to my research, one of the possible cause for the issue is: If your mail password contains a "#" then you should quote the environment string since everything after # will be taken as comment

    For example:

    MAIL_PASSWORD = r39304#d^fd  
    MAIL_PASSWORD = "r39304#d^fd"  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.

    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.

    Was this answer helpful?


Your answer

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