Some mail clients let you deliver mail to a script
https://serverfault.com/questions/506894/how-to-route-email-...
In that case you'd need to run a mail server where you install a script. I've done it with qmail and postfix but I haven't run my own mail server for a long time.
Another option is to use an existing mail server but write a script that polls the mail server with POP or IMAP.
Today I'd consider doing it serverless with something like
https://aws.amazon.com/about-aws/whats-new/2019/02/trigger-a...
So far as the "stack" I would go with any mainstream platform, mostly driven by what you like. You could certainly do this with Python, Java, .NET, etc.