Hi,
It looks like your question is more related to Development .To better solve your problem , I will add “Exchange Development” tag.
But based on my personal experience, this link seems mentioned the same problem to yours: azure active directory - Office 365 XOAUTH2 for SMTP on native clients 535 5.7.3 Authentication unsuccessful - Stack Overflow