Try to disable MFA and check.
Basic authentication in now disabled by default in Office 365, so you should avoid using it. Look at implementing oAuth in your see code https://video2.skills-academy.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth