Microsoft has deprecated “legacy” auth methods, which makes this sort of thing very difficult to accomplish nowadays.
I used to use IMAP/SMTP for Outlook Mail but they force you to use proprietary clients now, forcing OAuth. It makes scripting nearly impossible.
https://learn.microsoft.com/en-us/exchange/clients-and-mobil...