posted 3 years ago
Welcome to the Ranch, Nishant!
I can think of a couple of approaches. One is to make your notifications be log messages and use email logging channels. Downside is that you have to alter and re-deploy the app if the list changes and the work has to be done by a programmer or administrator.
Another is to code in all that logic into system "Z" and maybe get the routing and user information from a database. SQLite is a good choice if the app doesn't already have a database. Or, alternatively, Apache Derby. Downside is a lot of mail-handling code in the application that has to be written, debugged, and maintained.
The third option I can think of would be to use a mailing list system to do the actual routing. For example, GNU Mailman. Mailman allows you to define multiple mailing lists (topics) and to allow people to subscribe and unsubscribe to them, plus have customized delivery options such s to receive a periodic digest rather than immediate mail.
Mailman is a full dedicated web application, so there's some learning involved, but of course, you may find it useful for other purposes beyond the original Application Z, since it's a general-purpose mailer. Like most good apps these days, it's available as a Docker container, so actual installation and operation is much simpler than if you had to install the old-fashioned way (which is still an option). Mainly you have to define an administrative account and your lists and their eligibility and mailing options. Using this approach, Application Z can simply post to the appropriate list(s) and let Mailtman take care of the downstream routing.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.