Since 2023 you can not use neither Basic Authentication, nor SMTP AUTH for Microsoft Exchange Services anymore. Source: Deprecation of Basic authentication in Exchange Online
You have to choose between 2 following alternatives:
Implement OAuth authentication for SMTP as described in this Article: Authenticate an IMAP, POP or SMTP connection using OAuth
or
Use Microsoft Graph API instead, and more precisely Outlook mail API