Failed to authenticate on smtp server outlook in laravel.

Yosua Ferdian 6 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]
".

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,885 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,173 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Tasadduq Burney 8,361 Reputation points MVP
    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 |

    2 people found this answer helpful.

  2. Joyce Shen - MSFT 16,641 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.