Martin_Mueller , this sounds quite correct, yes. I am a PM and therefore did not implement it on my own, but we (a Java app polling for email to create cases per message) had to do roughly the following:
1. Configure AzureAD/Office 365 accordingly to instructions for non-interactive OAUTH (yes, each of your customers will have to do this in order for your app to be allowed to poll)
2. Introduce MSAL into our app (Java variant in our case of course)
3. Call MSAL with proper parameters configured in 1., this lib is handling the whole OAUTH flow, returning a token
4. Tell Javamail (the lib actually doing the authentication while polling/retrieving email) to use OAuth2 and giving it the token from 3.)
The documentation from MS was quite good on each part.
I'd recommend to set up a Office365 instance/account for testing as we did. It's just some bucks per month.